Created
January 13, 2018 10:44
-
-
Save IlyaFinkelshteyn/14750254656005c25c359371d7b4359f 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
# install https://github.com/travis-ci/travis.rb#installation | |
# get API token according https://developer.travis-ci.com/authentication | |
$env:TRAVIS_API_TOKEN = "<replace>" # must be secure variable set in Environment tab or YAML section | |
$env:TimeOutMins = <replace> # how long to wait for Travis build to complete (set in Environment tab or YAML section) | |
$headers = @{ | |
"Authorization" = "token $env:TRAVIS_API_TOKEN" | |
"Travis-API-Version" = "3" | |
} | |
[datetime]$stop = ([datetime]::Now).AddMinutes($env:TimeOutMins) | |
[bool]$success = $false | |
while(!$success -and ([datetime]::Now) -lt $stop) { | |
$builds = Invoke-RestMethod -Uri "https://api.travis-ci.org/builds?limit=10" -Headers $headers -Method Get | |
$currentBuild = $builds.builds | ? {$_.commit.sha -eq $env:APPVEYOR_REPO_COMMIT} | |
$success = $currentBuild.state -eq "passed" | |
if (!$success) {Start-sleep 5} | |
} | |
if (!$currentBuild) {throw "Could not get information about Travis build with sha $env:APPVEYOR_REPO_COMMIT"} | |
if (!$success) {throw "Travis build did not finished in $env:TimeOutMins minutes"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this snippet, @IlyaFinkelshtyn
I have made a little changed for my use case:
The switch case
"^(errored|failed|canceled)"
allows the script to fail quicker; instead of always waiting for success || timeout.