Skip to content

Instantly share code, notes, and snippets.

@sean-abbott
Created September 28, 2015 19:55
Show Gist options
  • Save sean-abbott/0be2eb509d694a27f07e to your computer and use it in GitHub Desktop.
Save sean-abbott/0be2eb509d694a27f07e to your computer and use it in GitHub Desktop.
from jenkins import Jenkins
from ConfigParser import RawConfigParser
import requests
import json
# read from /etc/jenkins_jobs/jenkins_jobs.ini
cfg = RawConfigParser()
cfg.read('/etc/jenkins_jobs/jenkins_jobs.ini')
args = dict(cfg.items('jenkins'))
args['username'] = args.pop('user')
my_jenkins = Jenkins(**args)
j_session = requests.Session()
j_session.auth = (args['username'], args['password'])
last_stable = j_session.get('{}job/Enterprise_Dockerized_Pipeline/lastStableBuild/api/json'.format(args['url']))
# would get BUILD_NUMBER in the meta job from jenkins
if last_stable.ok:
last_stable_dict = json.loads(last_stable.text)
build_number = last_stable_dict['number']
else:
build_number = 618
# get all the sub-jobs
subjobs = my_jenkins.get_build_info('Enterprise_Dockerized_Pipeline', build_number)['subBuilds']
# get slave where sub-job was built
out = dict([(sj['jobName'], my_jenkins.get_build_info(sj['jobName'], sj['buildNumber'])['builtOn']) for sj in subjobs])
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment