2
votes

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.

1
I suggest you select “Remove additional files at destination” and check if that solves your issue.AshokPeddakotla-MSFT
That 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

1 Answers

8
votes

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