Last active
February 8, 2018 03:21
-
-
Save IlyaFinkelshteyn/63684c78d14164cb501ff496dc68e43b to your computer and use it in GitHub Desktop.
This file contains hidden or 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_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