How to delete files from Azure Web App during VSTS deployment
Based on your description, seems you want to empty the destination folder before a new deployment.
If it is, then 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.
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.
Refer to Removing Deleted Files during Visual Studio Team Services Azure App Service Deploy Task for details.
Besides, you can also try the extenion Azure WebApp Virtual File System Tasks, it can delete files from Azure Web Apps through KUDU Virtual File System Rest API (Put & Get coming soon)
If that still not work, then you can write a script to delete the specific folder. But you need to make sure that the service account has the correct permission to access and delete the folder on Azure.
Alternately you can Remove-Item with Specific Credentica, below script for example:
Param(
[string]$computerName = "computername",
[string]$path ="E:\test\specific-folder"
)
$Username = "domain\user"
$Password = ConvertTo-SecureString "PasswordHere" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($Username,$password)
Invoke-Command -computername $computerName {Remove-Item -path $args[0] -Recurse} -cred $cred -ArgumentList $path
Related videos on Youtube
user3587624
Updated on June 04, 2022Comments
-
user3587624 almost 2 years
I have an Azure Web App where I store some data in the persistent storage of it. Through my VSTS Release Definition, I would like to remove a folder that gets filled in with data. The folder is located at D:\home\site\MyFolder.
Is there a way I can programatically remove the folder during deployment time from the VSTS Release Definition? I need to make sure that folder is empty every time a new deployment happens and at the moment I do that manually through the Kudu Web UI.
-
AshokPeddakotla-MSFT over 5 yearsI suggest you select “Remove additional files at destination” and check if that solves your issue.
-
user3587624 over 5 yearsThat is already checked on my Release definition but the folder I want to remove is outside of the wwwroot (D:\home\site\wwwroot) folder and it doesn't get removed.
-
-
user3587624 over 5 yearsGreat! I used your good information along with this other documentation: blog.kloud.com.au/2016/08/30/… Since my folder is outside of the wwwroot folder, I can't use the extension but it is good to know as I might move that folder inside and then leverage the extension.
-
RUKAclMortality over 4 yearsdoes not work. I had a *.Mobile.cshtml file - deleted it on source branch used for build artifact - it still get's served as it was not ever deleted from the server
-
Saad Awan about 4 yearsmy concern is that is there any why that i can totally delete files and folder from the path D:\home\site\MyFolder through 'console' under development tool or how i can use the mywebsite.azurewebsite.net/debug/console
-
Ryan Layton about 2 yearsWhen deploying to a linux app server the 'Remove Additional Files at destination' is not available. How do you remove files on a linux app service?