Azure App Service部署任务选项,可在部署时删除容器中的文件 [英] Azure App Service deploy task option to remove files in container upon deployment

查看:53
本文介绍了Azure App Service部署任务选项,可在部署时删除容器中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am deploying a python web app using Web App on Linux service and using a DevOps release pipeline. The pipeline task that I am using is called AzureRmWebAppDeployment@4.

在部署之间,未删除容器中的文件,这会引起问题.

Between deployments, the files in the container are not being removed and this is causing issues.

我注意到我是否使用其他类型的应用程序服务(即Windows上的Web App),并且如果部署方法设置为 Web Deploy ,则删除目标位置上的其他文件的选项存在(请参见屏幕截图).但是,我们使用的是 Zip Deploy 方法,并且更喜欢使用linux服务.如果没有将应用程序服务和部署方法结合在一起,则该选项对我不可用.

I noticed if I am using a different type of app service (i.e. Web App on Windows) and if the deployment method is set to Web Deploy the option for Remove additional files at destination exists (see screenshot). However we are using a Zip Deploy method and prefer to be using a linux service. without that combination of app service and deployment method, this option is not available to me.

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

Can anybody suggest an alternate method for deleting the container contents upon deployment? Also, any insight as to why this option is not available through the pipeline task when using Zip Deploy and Linux?

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

Thanks in advance for any help provided.

推荐答案

您可以使用

You can use kudu command api to clean the wwwroot folder on your webapp server. The kudu command rest api will execute the command in the specified directory on the server.

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


在Azure应用服务部署任务之前添加 Azure powershell 任务,然后运行内联脚本下方.


Add an Azure powershell task before Azure app service deploy task, and run below inline scripts.

$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 .

Above scripts will empty the folder /home/site/wwwroot before each deployment.

如果您需要删除应用服务器上的特定文件,则可以使用kudu delete rest api:

If you need to delete specific files on the app server, you can use kudu delete rest api:

DELETE /api/vfs/{path}
Delete the file at path.

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

For more examples you can check here.

这篇关于Azure App Service部署任务选项,可在部署时删除容器中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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