您可以使用kudu 命令 api来清理 webapp 服务器上的 wwwroot 文件夹。kudu 命令rest api 将command
在服务器上的指定目录中执行。
{
command = "find . -mindepth 1 -delete"
dir = "/home/site/wwwroot
}
在 Azure 应用服务部署任务之前添加一个Azure powershell任务,并在下面的内联脚本中运行。
$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.
有关更多示例,您可以在此处查看。