简体   繁体   English

如何通过API获取已完成的Jenkins作业的最终状态?

[英]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.

相关问题 如何使用 api 更新 jenkins 作业 - How can i update a jenkins job using the api Jenkins - 获取上次完成的构建状态 - Jenkins - Get last completed build status 我可以通过API获得Linkedin个人资料的活动状态吗? - Can I get Linkedin profile active status via API? Buildfire:如何有效地通过 API 从用户信息中获取订阅者状态? - Buildfire: How can I get subscriber status from user information via the API in an efficient way? 我如何架构轮询外部 API,该 API 以前为我提供了“已完成状态”的长时间运行的异步操作 ID? - How can I architect polling an external API that previously gave me long-running async operation ID for "Completed Status"? 如何确定 API 作业何时完成? - How to determine when an API job is completed? 如何通过API获取正在运行的jenkins作业的进度条数据 - how to get progress bar data for a running jenkins job through the API 如何获取发布到我的Web API的状态代码 - How can I get the status code of a post to my web api 如何使用 Facebook API,以及如何通过我的应用在用户墙上发布状态链接? - How to use the Facebook API, and how can I post a link with status on the users wall via my app? 如何通过soundcloud api调用获取用户ID? - How can I get a user id via soundcloud api call?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM