Created
June 14, 2019 23:36
-
-
Save OwenMcDonnell/6cced28d0abd311ddae794d78b58b2b4 to your computer and use it in GitHub Desktop.
Querying api for project history and filtering by branch
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
$env:API_TOKEN="your_api_token" # 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=100 # build history depth to search | |
$env:BRANCH="your_branch" # which branch's builds do you want to return | |
$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 $env:RECORDS_NUMBER | |
$result | % { | |
if($_.branch -eq $env:BRANCH){ | |
$build = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/build/$($_.version)" -Headers $headers -Method Get | |
$build | convertto-json | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment