Hashar has uploaded a new change for review. https://gerrit.wikimedia.org/r/75637
Change subject: publish-console.py script ...................................................................... publish-console.py script The lame python script would fetch a Jenkins HTML console on 127.0.0.1:8080 and published it under /logs/ web server. Requires python-requests. Change-Id: Iae1259250bade57ce67991c933b861744783e846 --- A bin/publish-console.py 1 file changed, 92 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/integration/jenkins refs/changes/37/75637/1 diff --git a/bin/publish-console.py b/bin/publish-console.py new file mode 100755 index 0000000..f3de0d2 --- /dev/null +++ b/bin/publish-console.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python + +"""Small script that will fetch a Jenkins HTML console and + "copy it under 'dest'. This is really hardcoded for Wikimedia usage. +""" + +import argparse +import os +import os.path +import requests + + +def parse_args(): + """Handle arguments passed to the script""" + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + '--jobname', dest='jobname', required=True, + help='Name of Jenkins job (BUILD_JOBNAME)' + ) + parser.add_argument( + '--buildnumber', dest='buildnumber', required=True, + help='Jenkins build number (BUILD_NUMBER)' + ) + parser.add_argument( + '--buildurl', dest='buildurl', required=True, + help='Full path to Jenkins build web page (BUILD_URL)' + ) + parser.add_argument( + '--zuulchange', dest='zuulchange', required=True, + help='Gerrit change number (ZUUL_CHANGE)' + ) + parser.add_argument( + '--zuulpatchset', dest='zuulpatchset', required=True, + help='Gerrit patchset (ZUUL_PATCHSET)' + ) + + parser.add_argument( + '--dest', dest='dest', default='/srv/org/wikimedia/integration/logs', + help='Base directory where logs will be saved' + ) + + return parser.parse_args() + + +def get_dest(options): + """Find out the local directory where log will be written""" + dest = os.path.join( + options.dest, + # Patchset 8 of change 12345 results in 45/12345,8 + options.zuulchange[-2:], + options.zuulchange + ',' + options.zuulpatchset, + options.jobname + '-' + options.buildnumber, + ) + + return dest + + +def get_console(options): + """Fetch HTML console content""" + # We want to hit Jenkins directly, saving SSL + Apache overhead + url_local = options.buildurl.replace( + 'https://integration.wikimedia.org/', + 'http://127.0.0.1:8080/') + # Craft the URL to fetch console from + url_console = url_local + '/logText/progressiveHtml' + + req = requests.get(url_console) + + return req.content + + +def main(): + """Main entry point, figure out dest dir and creates it, fetch the Jenkins + console and finally write it under 'console.html'""" + options = parse_args() + + dest = get_dest(options) + print "Publishing to %s" % dest + if not os.path.exists(dest): + os.makedirs(dest) + + print "Getting console from Jenkins" + console = "<pre>\n%s" % get_console(options) + + filename = os.path.join(dest, 'console.html') + print "Writing console to:\n%s" % filename + handle = open(filename, 'w') + handle.write(console) + + +if __name__ == '__main__': + main() -- To view, visit https://gerrit.wikimedia.org/r/75637 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iae1259250bade57ce67991c933b861744783e846 Gerrit-PatchSet: 1 Gerrit-Project: integration/jenkins Gerrit-Branch: master Gerrit-Owner: Hashar <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
