-
-
Save lowang-bh/41aa1706e91997c81987a9940399eb0e to your computer and use it in GitHub Desktop.
Tail Jenkins Jobs
This file contains hidden or 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
#!/usr/bin/env python | |
""" | |
Tail a Jenkins build in a terminal | |
""" | |
import os | |
import requests | |
import sys | |
import time | |
JENKINS_BASE = "https://example.com" | |
JENKINS_JOB = "build-software" | |
s = requests.Session() | |
s.auth = ( | |
os.environ.get('JENKINS_USERNAME', None), | |
os.environ.get('JENKINS_PASSWORD', None) | |
) | |
start = 0 | |
cont = True | |
while cont: | |
response = s.get( | |
'{base}/{job}/{job_number}' | |
'/logText/progressiveText?start={start}'.format( | |
base=JENKINS_BASE, job=JENKINS_JOB, | |
job_number=sys.argv[1], start=start | |
) | |
) | |
if response.status_code != 200: | |
print('Job complete or not found') | |
sys.exit(1) | |
if start != response.headers['X-Text-Size']: | |
print(response.text) | |
start = response.headers['X-Text-Size'] | |
try: | |
cont = response.headers['X-More-Data'] | |
except KeyError: | |
sys.exit(0) | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment