gpt4 book ai didi

azure-devops - Azure 应用服务部署任务选项,用于在部署时删除容器中的文件

转载 作者:行者123 更新时间:2023-12-04 14:14:08 27 4
gpt4 key购买 nike

我正在使用 Linux 服务上的 Web App 并使用 DevOps 发布管道部署 Python Web 应用程序。我正在使用的管道任务称为 AzureRmWebAppDeployment@4 .

在部署之间,容器中的文件不会被删除,这会导致问题。

我注意到我是否使用了不同类型的应用程序服务(即 Windows 上的 Web 应用程序)并且部署方法是否设置为 Web Deploy Remove additional files at destination 的选项存在(见截图)。但是我们使用的是 Zip Deploy方法,更喜欢使用 linux 服务。如果没有应用服务和部署方法的组合,我将无法使用此选项。

enter image description here

有人可以建议一种在部署时删除容器内容的替代方法吗?此外,对于为什么在使用 Zip Deploy 和 Linux 时无法通过管道任务使用此选项的任何见解?

在此先感谢您提供的任何帮助。

最佳答案

您可以使用 kudu command api清理 webapp 服务器上的 wwwroot 文件夹。 kudu 命令 rest api 将执行 command在服务器上的指定目录中。

{
command = "find . -mindepth 1 -delete"
dir = "/home/site/wwwroot
}

添加 Azure powershell Azure 应用服务部署任务之前的任务,并在内联脚本下运行。
$ResGroupName = ""
$WebAppName = ""

# Get publishing profile for web application
$WebApp = Get-AzWebApp -Name $WebAppName -ResourceGroupName $ResGroupName
[xml]$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp

# Create Base64 authorization header
$username = $publishingProfile.publishData.publishProfile[0].userName
$password = $publishingProfile.publishData.publishProfile[0].userPWD
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

$bodyToPOST = @{
command = "find . -mindepth 1 -delete"
dir = "/home/site/wwwroot"
}
# Splat all parameters together in $param
$param = @{
# command REST API url
Uri = "https://$WebAppName.scm.azurewebsites.net/api/command"
Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Method = "POST"
Body = (ConvertTo-Json $bodyToPOST)
ContentType = "application/json"
}
# Invoke REST call
Invoke-RestMethod @param

以上脚本将清空文件夹 /home/site/wwwroot在每次部署之前。

如果需要删除应用服务器上的特定文件,可以使用kudu delete rest api:
DELETE /api/vfs/{path}
Delete the file at path.

有关更多示例,您可以查看 here .

关于azure-devops - Azure 应用服务部署任务选项,用于在部署时删除容器中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62139151/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com