Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Last active February 8, 2018 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlyaFinkelshteyn/63684c78d14164cb501ff496dc68e43b to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/63684c78d14164cb501ff496dc68e43b to your computer and use it in GitHub Desktop.
$env:API_TOKEN="<your_api_key>" # use secure variable in case script runs from the build
$env:APPVEYOR_ACCOUNT_NAME="your_account_name" # no need to setup in case script runs from the build (default environment variable)
$env:APPVEYOR_PROJECT_SLUG="your_project_slug" # no need to setup in case script runs from the build (default environment variable)
$env:RECORDS_NUMBER=10 # build history depth to search
$headers = @{
"Authorization" = "Bearer $env:API_TOKEN"
"Content-type" = "application/json"
}
$history = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=$env:RECORDS_NUMBER" -Headers $headers -Method Get
$result = $history.builds | Where-Object {$_.status -eq "success"} | Sort-Object -Property created -Descending | Select-Object -First 1
#specify branch if needed:
#$result = $history.builds | Where-Object {$_.status -eq "success" -and $_.branch -eq "develop"} | Sort-Object -Property created -Descending | Select-Object -First 1
if (!$result) {Write-Warning "cannot find successfull build in last $env:RECORDS_NUMBER builds. Consider increasing RECORDS_NUMBER"} else {$result}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment