Publish-AzWebApp always cleans web app files, irrespective of -Clean option
Description
Publish-AzWebApp has a Clean option, described as follows: Cleans the target directory prior to deploying the file(s).
However, when I run Publish-AzWebApp, it always cleans the /site/wwwroot on the web app (both files and directories). This irrespective of whether -Clean is used. Also irrespective of whether -TargetPath is used.
This makes it impossible to use Publish-AzWebApp to copy my web site to the web app using several calls to Publish-AzWebApp. This is critical, because 1) my web site has over 6GB of files; 2) our developers need to be able to update part of the site while leaving other parts alone.
It is treacherous too - if you use Publish-AzWebApp without -Clean, you can expect it to not clean /site/wwwroot, while it does without even an error message.
Issue script & Debug output
I ran the lines below in Powershell 7, and verified the outcome in the web app using an FTP client.
Not sure what you mean with a "debug stream"
# Set up the test. copies productionadmin to dir /site/wwwroot/k in the web app
Publish-AzWebApp -ResourceGroupName $rg -Name $site -ArchivePath productionadmin.zip -TargetPath k
# copies productionadmin to dir /site/wwwroot/y in the web app. k has been removed
Publish-AzWebApp -ResourceGroupName $rg -Name $site -ArchivePath productionadmin.zip -TargetPath y
# copies productionadmin to dir /site/wwwroot/x in the web app. y has been removed
Publish-AzWebApp -ResourceGroupName $rg -Name $site -ArchivePath productionadmin.zip -TargetPath x -Clean:$false
# copies productionadmin to dir /site/wwwroot/z in the web app. x has been removed
Publish-AzWebApp -ResourceGroupName $rg -Name $site -ArchivePath productionadmin.zip -TargetPath z -Clean:0
# runs without error messages. but sowadmin is not copied to the web app at all. z is still there
Publish-AzWebApp -ResourceGroupName $rg -Name $site -ArchivePath sowadmin.zip -TargetPath /site/wwwroot/b
# copies sowadmin to /site/wwwroot. but z has been removed
Publish-AzWebApp -ResourceGroupName $rg -Name $site -ArchivePath sowadmin.zip
Environment data
Name Value
---- -----
PSVersion 7.4.1
PSEdition Core
GitCommitId 7.4.1
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module versions
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.15.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzConte…
Script 3.2.0 Az.Websites {Add-AzWebAppAccessRestrictionRule, Add-AzWebAppT…
Error output
There is no error output. Publish-AzWebApp seems to work fine.
We are experiencing this as well. Using Powershell 5.1 on Windows 11 with newly installed Az powershell modules. The app service is removing all files during the ZipDeploy even though we are not specifying the -Clean option.
Our command from our CI pipeline:
Publish-AzWebApp -ResourceGroupName $RESOURCE_GROUP_NAME -Name $APP_SERVICE_NAME -ArchivePath "deploy.zip" -Restart -Force
Do we have a solution to this issue? I am facing a similar issue.
@mperdeck @yogesh-ralegaonkar Thought you might like to know: it looks like this works correctly using Azure CLI instead of Azure Powershell.
I'm using this command:
az webapp deploy --resource-group $RESOURCE_GROUP_NAME --name $APP_SERVICE_NAME --slot $APP_SLOT_NAME --type zip --src-path deploy.zip --restart --clean false
@mperdeck @yogesh-ralegaonkar Thought you might like to know: it looks like this works correctly using Azure CLI instead of Azure Powershell.
I'm using this command:
az webapp deploy --resource-group $RESOURCE_GROUP_NAME --name $APP_SERVICE_NAME --slot $APP_SLOT_NAME --type zip --src-path deploy.zip --restart --clean false
Cheers, had the same issue and this worked as a workaround.
Hello,
We had the same issue. Using the -targetPath parameters seems the clean is not done. Just try it with -TargetPath to your wep app root folder like "c:\home\site\wwwroot" if it's a windows app service.
I just went through the same issue. I tried to deploy a zip file with some files that needed to be updated, without -Clean, but instead it deleted all other files and folders - at 2 am... I had to do an emergency full site deployment, not fun.
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 4.0.2 Az.Accounts {Add-AzEnvironment, Clear-AzConfig,
Script 3.3.0 Az.Websites {Add-AzWebAppAccessRestrictionRule,
Any update? It is open more than a year now.