如何在 Azure DevOps 部署之前使用 Powershell 或任何脚本删除 Azure 应用服务文件夹



你能帮我解决下面的问题吗 1.我已经在 Azure DevOps 中配置了 CI 2.In CD 中,我需要 Powerhell 或任何脚本,以便在部署之前删除 Azure 应用服务文件夹。 3.我也知道工藤的过程,但这个过程是手动的。

$WebAppName = “insert Web App name”
$slotName = “insert Slot Name”
$username = ‘insert the username from the publish profile’ #From the publish profile
$password = “insert the password from the publish profile” #From the publish profile
# Initialize parameters for Invoke-RestMethod
$apiUrl = “https://$WebAppName.scm.azurewebsites.net/api/vfs/site/wwwroot/”
if ($slotName -ne “”){
$apiUrl = “https://$webAppName`-$slotName.scm.azurewebsites.net/api/vfs/site/wwwroot/”
}
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((“$($username):$($password)”)))
$headers = @{
Authorization=“Basic $($base64AuthInfo)”
‘If-Match’ = ‘*’
}
$userAgent = “powershell/2.0”
# Define a reursive function to delete files
function DeleteKuduDir ($content, $dir)
{
foreach($c in $content)
{      
if($c.mime -eq “inode/directory”)
{
# Get listing of directory as an array
$childContent = Invoke-RestMethod –Uri $c.href –Headers $headers –UserAgent $userAgent –Method GET –ContentType “application/json”

# Delete directory
$newDir = $dir + (Split-Path $c.href –leaf) + “”
DeleteKuduDir –content $childContent –dir $newDir
}
# Delete file
$file = Split-Path $c.href –leaf
Write-Host “Deleting” $dir$file    
$result = Invoke-RestMethod –Uri $c.href –Headers $headers –UserAgent $userAgent –Method DELETE –ContentType “application/json”
}
}
# Get listing of wwwroot as an array
$rootContent = Invoke-RestMethod –Uri $apiUrl –Headers $headers –UserAgent $userAgent –Method GET –ContentType “application/json”
# Delete files and directory in wwwroot
DeleteKuduDir –content $rootContent –dir “”
Write-Host “Done!”

相关内容

最新更新