Last active
October 24, 2018 21:25
-
-
Save OwenMcDonnell/d1676c6a6d0b59f0c8c2d03b37881d8e to your computer and use it in GitHub Desktop.
appveyor multiple env deployments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[string]$environmentName1, | |
[string]$environmentName2, | |
[string]$buildVersion | |
) | |
$accountName = <your-account-name> | |
$projectSlug = <your-project-slug> | |
$token = $env:API_TOKEN #This should be added as a secure variable. Other variables used in script already exist | |
$headers = @{ | |
"Authorization" = "Bearer $token" | |
"Content-type" = "application/json" | |
} | |
$body1 = @{ | |
environmentName=$environmentName1 | |
buildVersion=$buildVersion | |
accountName=$accountName | |
projectSlug=$projectSlug | |
} | |
$body1 = $body1 | ConvertTo-Json | |
$deploymentId = (Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/deployments' -Headers $headers -Body $body1 -Method POST).deploymentId | |
[bool]$deploymentFinished = $false | |
[int]$retryCount = 0; | |
while (!$deploymentFinished) | |
{ | |
if ($retryCount -gt 10) | |
{ | |
throw "Reached maximum number of retries while waiting for deployment to complete" | |
} | |
$deploymentStatus = (Invoke-RestMethod -Uri "https://ci.appveyor.com/api/deployments/$deploymentId" -Headers $headers -Method Get).deployment.status | |
$deploymentFinished = $deploymentStatus -eq "success" | |
Write-Host "Current deployment status: $deploymentStatus" | |
Write-Host "Sleeping for 10 seconds before next check if deployment finished..." | |
Start-sleep 10 | |
$retryCount++ | |
} | |
Write-host "1st Deployment completed" -ForegroundColor Green | |
$body2 = @{ | |
environmentName=$environment2 | |
buildVersion=$buildVersion | |
accountName=$accountName | |
projectSlug=$projectSlug | |
} | |
$body2 = $body2 | ConvertTo-Json | |
$deploymentId = (Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/deployments' -Headers $headers -Body $body2 -Method POST).deploymentId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment