-
-
Save seandst/8e9b62f7b46bb5baa88a8bf5fbb11215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat /usr/bin/jenkies | |
#!/usr/bin/python | |
import warnings | |
from collections import defaultdict | |
from xml.etree.ElementTree import fromstring | |
import IPython | |
import jenkins | |
warnings.simplefilter("ignore") | |
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'])) | |
try: | |
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] | |
try: | |
demand[job_label] += 1 | |
except KeyError: | |
demand[job_label] = 1 | |
return demand | |
IPython.embed() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment