[英]How can I get the final status of a completed Jenkins job via API?
I make a call like: 我拨打电话如下:
http://jenkins.mysite.com/job/MYJOB/api/json?depth=2&tree=builds%5Bactions%5Bparameters%5Bname%2Cvalue%5D%5D%2Cnumber%2Cresult%5D http://jenkins.mysite.com/job/MYJOB/api/json?depth=2&tree=builds%5Bactions%5Bparameters%5Bname%2Cvalue%5D%5D%2Cnumber%2Cresult%5D
and get a result like: 并获得如下结果:
{
"builds": [{
"actions": [{
"parameters": [{
"name": "JT_BUILD_ID",
"value": "1274"
}]
}, {}, {}, {}, {}],
"number": 3,
"result": "SUCCESS"
}, {
"actions": [{
"parameters": [{
"name": "JT_BUILD_ID",
"value": "1273"
}]
}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
"number": 2,
"result": "SUCCESS"
}, {
"actions": [{
"parameters": [{
"name": "JT_BUILD_ID",
"value": "0"
}]
}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
"number": 1,
"result": "SUCCESS"
}]
}
I am passing JT_BUILD_ID so I can match to this run of MYJOB. 我正在传递JT_BUILD_ID,所以我可以匹配MYJOB的这个运行。
When I find the matching JT_BUILD_ID, I look at result and when I see SUCCESS I assume I am done. 当我找到匹配的JT_BUILD_ID时,我看结果,当我看到SUCCESS时,我认为我已经完成了。 But the job is still running do to post build actions.
但是这项工作仍在运行,以发布构建行动。
How can I both match the instance of the build (using the parameter JT_BUILD_ID) and detect the final status of the job? 我怎样才能匹配构建实例(使用参数JT_BUILD_ID)并检测作业的最终状态?
There is another key building
under builds
, if the post-build is still working, the status will be kept as true
. 在
building
下还有另一个关键builds
,如果builds
后仍在工作,状态将保持为true
。 It turns to false
when the job is totally completed. 当工作完全完成时,它变为
false
。
Therefore you can add extra check for building == false
, the final url looks like below 因此,您可以为
building == false
添加额外的检查,最终的URL如下所示
https://ci.jenkins-ci.org/view/Libraries/job/lib-jira-api/api/json/?pretty=true&depth=2&tree=builds[actions[parameters[name,value]],number,result,building] https://ci.jenkins-ci.org/view/Libraries/job/lib-jira-api/api/json/?pretty=true&depth=2&tree=builds[actions[parameters[name,value]],number,result ,建造]
The result could be like below in your case if latest build is ongoing (in post-build phase) 如果最新版本正在进行(在构建后阶段),结果可能如下所示
{
"builds": [{
"actions": [{
"parameters": [{
"name": "JT_BUILD_ID",
"value": "1274"
}]
}, {}, {}, {}, {}],
"building" : true,
"number": 3,
"result": "SUCCESS"
}, {
"actions": [{
"parameters": [{
"name": "JT_BUILD_ID",
"value": "0"
}]
}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
"building" : false,
"number": 1,
"result": "SUCCESS"
}]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.