Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Last active September 8, 2018 01:18
Show Gist options
  • Save IlyaFinkelshteyn/d0e6f92a73824ecb1f7fd0a053bd1407 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/d0e6f92a73824ecb1f7fd0a053bd1407 to your computer and use it in GitHub Desktop.
#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