Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save wehappyfew/ca120d8cbb50c564a3bb to your computer and use it in GitHub Desktop.

Select an option

Save wehappyfew/ca120d8cbb50c564a3bb to your computer and use it in GitHub Desktop.
Do you have an insane number of jenkins and you want to build on all of them? This is for you. The code makes the build one at a time. I shall make it run in parallel.
def build_jenkins(j_user, j_pass, j_url, job_name):
"""
# https://github.com/stackforge/python-jenkins
# http://python-jenkins.readthedocs.org/en/latest/index.html
"""
import time
from jenkins import Jenkins
# set the jenkins object
j = Jenkins(j_url, j_user, j_pass)
if j.job_exists(job_name) is True:
j.build_job(job_name)
print("\n Build command sent to Jenkins: %s \n"%j_url)
print("Wait for the build to complete....")
time.sleep(15)
last_b = j.get_job_info(job_name)['lastCompletedBuild']['number']
last_successful_b = j.get_job_info(job_name)['lastSuccessfulBuild']['number']
# print last_b , last_successful_b #for debugging
# print "Take extra build info from this:\n" , j.get_job_info(job_name) # for debugging
print "Checking last build ... "
print "Last build : %s" % last_b
print "Last successful build : %s" % last_successful_b, "\n"
# time.sleep(10)
if last_b == last_successful_b:
print "-- Build success --"
else:
print "Failed build :["
# Build all locust slaves
jenkins_urls = []
for i in range(1,11):
# create the jenkins url
jenkins_url = "http://host%s.site.com:8686/"%i
# add the jenkins url to the list
jenkins_urls.append(jenkins_url)
# print jenkins_urls #for debugging
for url in jenkins_urls:
build_jenkins(j_user="username", j_pass="password", j_url=url, job_name='JobName')
@wehappyfew
Copy link
Copy Markdown
Author

Note to myself: Make it run in parallel ! :]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment