Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#This script can be used as a deployment script to make environment deployment synchronous.
$token = $env:API_TOKEN #This should be added as a secure variable. Other verisables used in script already exist
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
$body = @{
environmentName=<Your_Environment_Name>
accountName=$env:APPVEYOR_ACCOUNT_NAME
projectSlug=$env:APPVEYOR_PROJECT_SLUG
buildVersion=$env:APPVEYOR_BUILD_VERSION
buildJobId=$env:APPVEYOR_JOB_ID
}
$body = $body | ConvertTo-Json
$deploymentId = (Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/deployments' -Headers $headers -Body $body -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 "Deployment completed" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.