Skip to content

Instantly share code, notes, and snippets.

Created Sep 2, 2016
What would you like to do?
$ cat /usr/bin/jenkies
import warnings
from collections import defaultdict
from xml.etree.ElementTree import fromstring
import IPython
import jenkins
j = jenkins.Jenkins('redacted', username='redacted', password='redacted')
user = j.get_whoami()
version = j.get_version()
print('Hello %s from Jenkins %s' % (user['fullName'], version))
def label_demand():
demand = dict()
for queued_job in j.get_queue_info():
task_name = queued_job['task']['name']
print('Checking queued task {}'.format(queued_job['id']))
job_config = fromstring(j.get_job_config(task_name))
job_label = job_config.find('assignedNode').text
except jenkins.NotFoundException:
# job with task name not found, so assuming it's a "node-type=<label>" expression
job_label = task_name.split('=', 1)[1]
demand[job_label] += 1
except KeyError:
demand[job_label] = 1
return demand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment