如何从命令行检查Jenkins构建的构建状态?

Modified on: Mon, 29 Apr 2019 16:40:02 +0800

如何在不切换到浏览器的情况下检查Jenkins构建状态?

如果需要,我可以使用JSON API创建一个脚本,但我想知道是否已经内置了这样的内容。

作者:,Catskul

最佳答案

我找不到内置工具,所以我做了一个:

#!/usr/bin/python # # author: ajs # license: bsd # copyright: re2 import json import sys import urllib import urllib2 jenkinsUrl = "https://jenkins.example.com/job/" if len( sys.argv ) > 1 : jobName = sys.argv[1] jobNameURL = urllib.quote(jobName) else : sys.exit(1) try: jenkinsStream = urllib2.urlopen( jenkinsUrl + jobNameURL + "/lastBuild/api/json" ) except urllib2.HTTPError, e: print "URL Error: " + str(e.code) print " (job name [" + jobName + "] probably wrong)" sys.exit(2) try: buildStatusJson = json.load( jenkinsStream ) except: print "Failed to parse json" sys.exit(3) if buildStatusJson.has_key( "result" ): print "[" + jobName + "] build status: " + buildStatusJson["result"] if buildStatusJson["result"] != "SUCCESS" : exit(4) else: sys.exit(5) sys.exit(0)


相关问答

添加新评论