As part of my build process in VSTS I want to delete all files and folders (except af few) from my azure site before a new deploy. My guess is, that using a Azure Powershell script would be a good idea and I would prefer making an inline script.
I am using Azure Resource Manager as connection type, I have selected my subscription and script type (Inline Script) but then I am lost, how do i select my app service and, for a start, list my files?
Trying just, this for a test, only gives my files in my VSTS environment
Get-ChildItem -Path $(build.sourcesDirectory)
Here's a tweaked version of the script which should be included in your project and exported as an artefact as part of your build, I call mine Delete-WebAppFiles.ps1
It expands on the previous answer by also handling virtual applications and having error handling for the case when the files do not exist e.g. on first deployment to a new environment
You can then add a Powershell task as mentioned above which should look a little like this...
First, it’s better to include the files to the project that the web app needs, then just check Remove additional files at destination option (Check Publish using Web Deploy option first) to remove additional files.
Secondly, you can remove the files through Kudu API.
More information, you can refer to: Interacting with Azure Web Apps Virtual File System using PowerShell and the Kudu API
Update (Add Kudu sample):
Script: