Last active
December 14, 2015 08:28
-
-
Save andylind/5057436 to your computer and use it in GitHub Desktop.
This script prints the status of a set of Jenkins jobs in color (works on windows only). Example Usage: "C:\Python33\python.exe" build_status.py https://ci.jenkins-ci.org/view/Jenkins%20core/api/json
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
def set_text_color(color): | |
#This method works on windows only | |
color_codes = {"BLUE" : 0x0001, "GREEN" : 0x0002, "RED" : 0x0004, "MAGENTA" : 0x0005, "YELLOW" : 0x0006, "GRAY" : 0x0007} | |
STD_OUTPUT_HANDLE = -11 | |
from ctypes import windll, Structure, c_short, c_ushort, byref | |
stdout_handle = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) | |
SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute | |
SetConsoleTextAttribute(stdout_handle, color_codes[color]) | |
def print_build_status(jenkins_url): | |
import json, urllib.request | |
request = urllib.request.urlopen(jenkins_url) | |
encoding = request.headers.get_content_charset() | |
data = json.loads(request.read().decode(encoding)) | |
for job in data['jobs']: | |
if 'anime' in job['color']: | |
job['name'] = job['name'] + ' Running...' | |
if 'blue' in job['color']: | |
set_text_color("GREEN") | |
print("+ " + job['name']) | |
elif 'yellow' in job['color']: | |
set_text_color("YELLOW") | |
print("- " + job['name']) | |
elif 'red' in job['color']: | |
set_text_color("RED") | |
print("- " + job['name']) | |
elif 'aborted' in job['color']: | |
set_text_color("GRAY") | |
print("- " + job['name']) | |
else: | |
set_text_color("MAGENTA") | |
print("- " + job['name']) | |
import sys | |
print_build_status(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment