Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete files from Azure Web App during VSTS deployment

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.

like image 707
user3587624 Avatar asked Oct 20 '25 02:10

user3587624


1 Answers

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.

enter image description here

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
like image 191
Andy Li-MSFT Avatar answered Oct 21 '25 18:10

Andy Li-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!