Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
Last active August 29, 2015 14:22
Show Gist options
  • Save wehappyfew/d384e3edc264c76bb1b6 to your computer and use it in GitHub Desktop.
Save wehappyfew/d384e3edc264c76bb1b6 to your computer and use it in GitHub Desktop.
Build the current branch of a provided job
def build_jenkins(j_url="http://11.11.11.11:8686/", job_name='SuperJob'):
"""
Build the current branch of a provided job
"""
import time
from jenkins import Jenkins, JenkinsError
# http://jenkins-webapi.readthedocs.org/en/latest/
j = Jenkins(j_url, j_user, j_pass)
j.job_build(job_name) ; print("\nBuild command sent!\n")
print("Wait for the build to complete....") ; time.sleep(15)
last_b = j.job_last_build(job_name)
last_successful_b = j.job_last_successful_build(job_name)
print "Checking last build ... "
print "Last build : %s" % last_b.number
print "Last successful build : %s" % last_successful_b.number, "\n"
# time.sleep(10)
if last_b.number == last_successful_b.number:
print "-- Build success --"
else:
print "Failed build :["
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment