Skip to content

Instantly share code, notes, and snippets.

@andrewdmcleod
Created August 28, 2018 09:34
Show Gist options
  • Save andrewdmcleod/3e2847e17cccf4c12385d2c1ddcbe20c to your computer and use it in GitHub Desktop.
Save andrewdmcleod/3e2847e17cccf4c12385d2c1ddcbe20c to your computer and use it in GitHub Desktop.
jenkins pipeline aggregator viewer python script
#!/usr/bin/python3
import urllib.request, json , os, time, keyboard
class bcolors:
HEADER = '\033[95m'
IN_PROGRESS = '\033[94;5m'
SUCCESS = '\033[92m'
WARNING = '\033[93m'
FAILED = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
INV_ON = '\033[7m'
INV_OFF = '\033[27m'
numBuilds = 30
pipelineUrl = "http://JENKINS:8080/job/JOB_NAME/"
os.system('clear')
count = 1
while True:
print("\033[0;0H")
with urllib.request.urlopen(pipelineUrl + "/api/json/") as url:
data = json.loads(url.read().decode())
thingy = []
for build in data['builds'][:numBuilds]:
buildId = build['number']
print("\r")
if count % 2 == 0:
INV = bcolors.INV_ON
else:
INV = bcolors.INV_OFF
count += 1
thingy = []
with urllib.request.urlopen("{}/{}/wfapi/describe".format(pipelineUrl,buildId)) as wfapiurl:
wfdata = json.loads(wfapiurl.read().decode())
buildnum = "[ {} ]".format(wfdata['id'])
print(bcolors.HEADER + bcolors.ENDC + buildnum, end='')
for stage in wfdata['stages']:
methodcall = getattr(bcolors, stage['status'])
thingy.append([methodcall + stage['name'], "\t"])
print (methodcall + INV + stage['name'], "\t", end='')
print(" ", end='')
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment