如何在VSTS部署期间从Azure Web App中删除文件

问题描述 投票:0回答:1

我有一个Azure Web应用程序,我将一些数据存储在它的持久存储中。通过我的VSTS版本定义,我想删除一个填充数据的文件夹。该文件夹位于D:\ home \ site \ MyFolder。

有没有办法在VSTS版本定义的部署时间内以编程方式删除文件夹?我需要确保每次新部署发生时文件夹都是空的,并且我现在通过Kudu Web UI手动执行该操作。

azure azure-devops azure-web-sites
1个回答
4
投票

根据您的描述,您似乎希望在新部署之前清空目标文件夹。

如果是,则在使用Azure App Service Deploy任务时,如果您正在使用“使用Web Deploy发布”选项,则还可以选择“在目标中删除其他文件”。

如果选中此选项,则部署过程将删除目标中正在部署的程序包中没有相应文件的任何文件。

换句话说,它将删除不再需要的先前部署中的任何遗留文件。

有关详细信息,请参阅Removing Deleted Files during Visual Studio Team Services Azure App Service Deploy Task

enter image description here

此外,您还可以尝试扩展Azure WebApp Virtual File System Tasks,它可以通过KUDU虚拟文件系统Rest API从Azure Web Apps中删除文件(Put&Get即将推出)

如果仍然无效,则可以编写脚本来删除特定文件夹。但您需要确保服务帐户具有访问和删除Azure上的文件夹的正确权限。

或者你可以使用特定的Credentica删除项目,例如:

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
© www.soinside.com 2019 - 2024. All rights reserved.