Skip to content

Instantly share code, notes, and snippets.

@cmheisel
Created October 20, 2012 00:41
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 cmheisel/3921453 to your computer and use it in GitHub Desktop.
Save cmheisel/3921453 to your computer and use it in GitHub Desktop.
Check build status with travis before deploying
def ci(branch):
import requests, json, time
r = requests.get('http://travis-ci.org/%s/%s/builds.json' % (USERNAME, REPO))
assert r.status_code == 200
assert 'json' in r.headers['content-type']
data = json.loads(r.read())
builds_by_branch = {}
for build in data:
builds_for_branch = builds_by_branch.get(build['branch'], [])
builds_for_branch.append(build)
builds_for_branch.sort(key=lambda b: b.get('started_at'))
builds_for_branch.reverse()
builds_by_branch[build['branch']] = builds_for_branch
try:
build = builds_by_branch[branch][0]
except (KeyError, IndexError):
print "Build not submitted for %s yet, waiting..." % branch
time.sleep(120)
ci(branch)
if build['result'] is None:
print "Build not finished, waiting..."
time.sleep(90)
ci(branch)
elif build['result'] != 0:
url = "https://travis-ci.org/#!/cmheisel/kardboard/builds/%s" % build['id']
raise Exception("FAIL: Build %s not passed, result: %s -- %s" % (build['number'], build['result'], url))
msg = "PASSED %s: %s" % (build['branch'], build['message'])
print msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment