Skip to content

Instantly share code, notes, and snippets.

@m-mizutani
Created March 19, 2013 23:30
Show Gist options
  • Save m-mizutani/5201104 to your computer and use it in GitHub Desktop.
Save m-mizutani/5201104 to your computer and use it in GitHub Desktop.
For Post build task of Jenkins
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import json
import subprocess
import os
import time
conf = {'host': 'localhost',
'port': 8080,
'proj_name': 'shiso-local',
'sound': '/Users/masa/works/jenkins/mdai.mp3',
'growl': '/usr/local/bin/growlnotify',
}
def main ():
global conf
build_id = os.environ.get ('BUILD_ID')
while True:
fd = urllib.urlopen ('http://localhost:8080/job/shiso-local/lastBuild/api/json')
buf = ''
for a in fd: buf += a
jdata = json.loads (buf)
print jdata
if build_id is None or build_id == jdata['id']: break
time.sleep (1.0)
if jdata['result'] != 'SUCCESS':
if 'growl' in conf:
subprocess.call ([conf['growl'], '-t', 'Jenkins', '-m', jdata['fullDisplayName'] + ': ' + jdata['result']])
if 'sound' in conf:
subprocess.call (['/usr/bin/afplay', conf['sound']])
if __name__ == '__main__':
print os.environ
main ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment