imgen
imgen

Reputation: 3133

How to clean up wwwroot folder on the target Azure Websites Windows Server before each deployment in VSTS

After about a dozen deployments, the wwwroot directory is filled with a lot of files due to active development and deployments. We are using VSTS's Azure App Service Deploy task to deploy to Azure Websites Windows Server for a ASP.NET Web API project, is there a way to clean up the wwwroot directory before deploying to the Avsts pre-deployment clean up?

Upvotes: 34

Views: 30963

Answers (4)

Andy
Andy

Reputation: 180

If using App Service Linux you can't use web deploy and the "Remove Additional Files at Destination" option is not possible.

A workaround in this case is to use the 'Post Deployment Action' with an 'inline script' set to: rm -rf /home/site/wwwroot/*

You can have 2x Azure App Service deploy tasks, the first one deploying anything (for example, an empty zip file) and including the above script, the 2nd task to deploy your app code.

This approach is only suitable if you are using a deployment slot and slot swap, (which is recommended anyway), otherwise your app will break during deployment when the files are deleted!

Upvotes: 2

Alexander S.
Alexander S.

Reputation: 844

For Web Deploy use answer by @Brendan Green.

For Zip Deploy, from Kudu documentation:

When a new build is deployed with zipdeploy, files and directories that were created by the previous deployment but are no longer present in the build will be deleted. Any other files and directories found in the site that aren't being overwritten by the deployment, such as those placed there via FTP or created by your app during runtime, will be preserved.

https://github.com/projectkudu/kudu/wiki/Deploying-from-a-zip-file-or-url

I think it's good enough for most cases.

Upvotes: 3

Gerard
Gerard

Reputation: 2709

For a manually process and for those not having VSTS, you can use Kudu console to delete the files/folders in Azure Web App.

To access the site/files through the Kudu console use the below URL.

https://****.scm.azurewebsites.net/ (enter your website name instead of ****)

Click on the Debug Console -> PowerShell to open a console along with files, then select and delete the files/folders using the option available.

Upvotes: 4

Brendan Green
Brendan Green

Reputation: 11954

When using the Azure App Service Deploy task, and you are using the Publish using Web Deploy option, there is an additional option to Remove Additional Files at Destination.

enter image description here

If you check this option, the deployment process will remove any files at the destination where there is no corresponding file in the package that is being deployed.

In other words, it'll remove any left over files from a previous deployment that are no longer required.

Upvotes: 61

Related Questions