Skip to content

Instantly share code, notes, and snippets.

@daicham
Created January 11, 2013 01:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daicham/4507191 to your computer and use it in GitHub Desktop.
Save daicham/4507191 to your computer and use it in GitHub Desktop.
Request jenkins job by http on Python (Tested for Mercurial)
# usage:
# python jenkins.py jobname1, jobname2
import sys, httplib
JENKINS_HOST = 'localhost:8080'
URL = '/jenkins/job/%s/build?token=%s&cause=%s'
JENKINS_AUTH_TOKEN = 'token'
CAUSE='Requested%20by%20Python'
jenkins_job_ids = sys.argv
jenkins_job_ids.pop(0) # shift operation to reduce this command
for job_id in jenkins_job_ids:
http = httplib.HTTPConnection(JENKINS_HOST)
url = URL % (job_id, JENKINS_AUTH_TOKEN, CAUSE)
http.request('GET', url)
response = http.getresponse()
#print response.status, response.reason, url # debug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment