Skip to content

Instantly share code, notes, and snippets.

@MattJeanes
Created May 11, 2020 00:40
Show Gist options
  • Save MattJeanes/c3a074a459ef928a555ed4e70b408091 to your computer and use it in GitHub Desktop.
Save MattJeanes/c3a074a459ef928a555ed4e70b408091 to your computer and use it in GitHub Desktop.
Native powershell implementation of Publish-AzWebApp (currently C# based)
$publishingUsername = '$xxx'
$publishingPassword = 'xxx'
$scmUri = 'https://xxx.scm.azurewebsites.net'
$zipFile = "xxx.zip"
$deployUrl = "$scmUri/api/zipdeploy?isAsync=true"
$deployStatusUrl = "$scmUri/api/deployments/latest"
$byteArray = [System.Text.Encoding]::ASCII.GetBytes($publishingUsername + ":" + $publishingPassword)
$authHeader = "Basic $([Convert]::ToBase64String($byteArray))"
$headers = @{
"Authorization" = $authHeader
"Content-Type" = "application/zip"
}
$null = Invoke-WebRequest -Method POST -Headers $headers -Uri $deployUrl -InFile $zipFile
Write-Host "Sent zip file"
$numStatusChecks = 600
$numChecks = 0;
$result = $null
do
{
Start-Sleep -Seconds 2
$result = Invoke-WebRequest -Headers $headers -Uri $deployStatusUrl
$numChecks++;
Write-Host "Check $numChecks - status is currently $([System.Net.HttpStatusCode]$result.StatusCode)"
} while ($result.StatusCode -eq [int][System.Net.HttpStatusCode]::Accepted -and $numChecks -lt $numStatusChecks);
if ($result.StatusCode -eq [int][System.Net.HttpStatusCode]::Accepted -and $numChecks -ge $numStatusChecks)
{
Write-Error "Maximum status polling time exceeded. Deployment is still in progress."
}
elseif ($result.StatusCode -ne [int][System.Net.HttpStatusCode]::OK)
{
Write-Error "Deployment failed with status code " + $result.StatusCode
}
else {
Write-Host "Deployment successful"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment