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

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

问题描述

我有一个 Azure Web 应用程序,我将一些数据存储在它的持久存储中.通过我的 VSTS Release Definition,我想删除一个填充了数据的文件夹.该文件夹位于 D:homesiteMyFolder.

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

解决方案

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

如果是,那么在使用 Azure 应用服务部署任务时,并且您正在使用使用 Web 部署发布选项,是用于删除目标位置的其他文件的附加选项.

如果选中此选项,部署过程将删除目标位置的所有文件,如果正在部署的包中没有相应文件.

换言之,它将从以前的部署中删除不再需要的任何剩余文件.

参考

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

如果还是不行,那么你可以写一个脚本来删除特定的文件夹.但是您需要确保服务帐户具有访问和删除 Azure 上文件夹的正确权限.

或者,您可以使用特定 Credentica 删除项目,例如以下脚本:

参数([string]$computerName = "计算机名",[string]$path ="E:	estspecific-folder")$用户名 = "域用户"$Password = ConvertTo-SecureString "PasswordHere" -AsPlainText -Force$cred = 新对象 System.Management.Automation.PSCredential($Username,$password)Invoke-Command -computername $computerName {Remove-Item -path $args[0] -Recurse} -cred $cred -ArgumentList $path

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:homesiteMyFolder.

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.

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:	estspecific-folder"
)
$Username = "domainuser"
$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天全站免登陆