VSTS部署期间如何从Azure Web App删除文件 [英] How to delete files from Azure Web App during VSTS deployment

查看:92
本文介绍了VSTS部署期间如何从Azure Web App删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure Web App,我在其中将一些数据存储在其持久性存储中.通过我的VSTS版本定义,我想删除一个充满数据的文件夹.该文件夹位于 D:\ home \ site \ MyFolder .

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.

有没有一种方法可以在部署期间从VSTS版本定义中以编程方式删除该文件夹?我需要确保每次进行新部署时该文件夹都为空,此刻我需要通过Kudu Web UI手动进行操作.

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.

推荐答案

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

Based on your description, seems you want to empty the destination folder before a new deployment.

如果是,则在使用 Azure App Service Deploy 任务时,并且您正在使用使用Web Deploy发布选项,是在目标位置删除其他文件的另一种选择.

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.

请参阅

此外,您还可以尝试扩展 Azure WebApp虚拟文件系统任务,它可以通过KUDU虚拟文件系统Rest API(Put& Get now)来从Azure Web Apps删除文件

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)

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

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.

或者,您可以使用以下脚本来删除带有特定Credentica的物品:

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

这篇关于VSTS部署期间如何从Azure Web App删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆