Last active
February 12, 2018 21:19
-
-
Save t3knoid/3cffa2d5ac8996ae781a35a8d9fc55d7 to your computer and use it in GitHub Desktop.
Pregressively read a Jenkins job console using Python
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
import urllib | |
import urllib2 | |
import time | |
import sys | |
JENKINS_BASE = # Set to Jenkins base URL | |
JENKINS_JOB = # Set to Jenkins job | |
start = 0 # | |
job_number='lastBuild' # Get the last build | |
cont = True # This semaphore will be used to indicate whether or not to read more data | |
while cont: | |
response = urllib2.urlopen( | |
'{base}/{job}/{job_number}' | |
'/logText/progressiveText?start={start}'.format( | |
base=JENKINS_BASE, job=JENKINS_JOB, | |
job_number=job_number, start=start | |
) | |
) | |
if response.getcode() != 200: | |
print('Job complete or not found') | |
sys.exit(1) | |
if start != response.info().get('X-Text-Size'): | |
for line in response: | |
print line.rstrip() | |
start = response.info().get('X-Text-Size') // | |
cont = response.info().get('X-More-Data') # Build is in progress need to request more data | |
time.sleep(2) # Add some delay before requesting more data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment