Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$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
You can’t perform that action at this time.