views.py
在这里,我可以获得当前正在运行的jenkins作业构建的所有信息。但是当用户再次运行或触发相同的作业时,它将在jenkins上排队,但作为待定构建。 所以我得到当前正在运行的作业的构建ID,而不是待定的jenkins构建。 Actualy我想要构建待定版本的ID。
try:
print "in try.."
jenkinsStream = urllib2.urlopen( "http://10.211.213.138:8080/job/TE-mobius/lastBuild/api/json?pretty=true" )
print "after fetching url"
except urllib2.HTTPError, e:
print "URL Error: " + str(e.code)
print " (job name [" + jobName + "] probably wrong)"
try:
print "Before loading json"
buildStatusJson = json.load( jenkinsStream )
print "After loading json"
except:
print "Failed to parse json"
print "before while.."
print buildStatusJson["building"]
#print "[" + jobName + "] duration: " + str(buildStatusJson["duration"])
print buildStatusJson.has_key( "result" )
if buildStatusJson.has_key( "result" )==True:
print "in if"
print "[" + jobname + "] duration: " + str(buildStatusJson["duration"])
print "[" + jobname + "] building: " + str(buildStatusJson["building"])
print "[" + jobname + "] timestamp: " + str(buildStatusJson["timestamp"])
print "[" + jobname + "] url: " + str(buildStatusJson["url"])
print "[" + jobname + "] result: " + str(buildStatusJson["result"])
print "[" + jobname + "] build number: " + str(buildStatusJson["number"])
print "[" + jobname + "] JobName: " + str(buildStatusJson["fullDisplayName"])
答案 0 :(得分:1)
http://10.211.213.138:8080/job/TE-mobius/api/json?pretty=true
处的API端点有一个nextBuildNumber
密钥。
它也有
"queueItem" : {
"blocked" : false,
"buildable" : true,
"id" : 119,
"inQueueSince" : 1401783373284,
"params" : "",
"stuck" : false,
"task" : {
"name" : "YourJobName",
"url" : "http://jenkins/job/YourJobName/"
},
"url" : "queue/item/119/",
"why" : "Waiting for next available executor",
"buildableStartMilliseconds" : 1401783373290,
"pending" : false
}
提供有关该待处理构建的一些基本信息。在构建开始之前,Jenkins中不会存在您尝试在代码中打印的某些构建信息。
不幸的是,这只会让你获得下一个待定版本的内部版本号。如果您在一个作业的队列中有参数化构建和多个构建,我不知道有任何方法可以获取其他待处理构建的构建号。如果需要,可能需要编写插件。