Skip to content

Instantly share code, notes, and snippets.

@vmalloc
Created August 23, 2011 13:44
Show Gist options
  • Save vmalloc/1165155 to your computer and use it in GitHub Desktop.
Save vmalloc/1165155 to your computer and use it in GitHub Desktop.
Script to poll a jenkins job and run growlnotify with the status at its end
import time
import argparse
import urllib2
import lxml.etree
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument("--sleep", default=1, type=int)
parser.add_argument("server")
parser.add_argument("job")
if __name__ == '__main__':
args = parser.parse_args()
while True:
xml = lxml.etree.fromstring(urllib2.urlopen("http://{args.server}/job/{args.job}/api/xml".format(args=args)).read())
[status] = xml.xpath("color/text()")
if status in ("blue", "red"):
subprocess.Popen("growlnotify -s -t \"{}\" -m \"Build {}\"".format(
args.job, "succeessful" if status == "blue" else "failed"
), shell=True)
break
time.sleep(args.sleep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment