从队列ID获取Jenkins Job Build ID [英] Get Jenkins Job Build ID from Queue ID

查看:114
本文介绍了从队列ID获取Jenkins Job Build ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以成功地使用它来启动詹金斯工作:

I'm successfully able to use this to kick off a Jenkins Job:

curl -X POST "http://jenkins_srv:8080/job/MY_JOB/buildwithParameters?this=1&that=2" --user name:pass

我还可以使用以下命令从此作业中获取consoleText:

I can also get the consoleText from this job using:

curl -X POST "http://jenkins_srv:8080/job/MY_JOB/lastBuild/consoleText"

但是,如果我背靠背运行多个作业,这将无法扩展.我注意到第一个curl命令返回的内容包括:

However, this doesn't scale if I run multiple jobs back to back. I've noticed that the first curl command has a return that includes:

Location: http://jenkins_srv:8080/queue/item/123/

我假设 123 是作业队列ID.

I'm assuming that 123 is the job queue id.

我的问题是,如果我将作业 121 122 ,& 123 背对背,我该怎么用以检查作业队列项目 122 的状态?另外,我该怎么用以确定工作队列项目 122 最终导致的实际构建ID?

My question is, if I queue jobs 121, 122, & 123 back to back, what do I use to check the status of job queue item 122? Also, what do I use to determine the actual build id that eventually resulted from job queue item 122?

推荐答案

假设您的位置为 http://jenkins_srv:8080/queue/item/123/,则可以获取http://jenkins_srv:8080/queue/item/123/api/json?pretty = true 以返回有关该队列项目的信息(您也不能包含?pretty = true 如果您不关心格式,或者如果要以XML格式显示结果,请使用 api/xml .

Assuming that you have a location of http://jenkins_srv:8080/queue/item/123/, you can GET http://jenkins_srv:8080/queue/item/123/api/json?pretty=true to return information about that queue item (you can also not include ?pretty=true if you don't care about formatting, or use api/xml if you want the results in XML).

我不知道队列API上是否有标准文档,但是看来,如果队列项目已完成(也许也是当前正在构建?),它将有一个 executable 节点..适用于我的服务器的服务器看起来像这样:

I don't know if there's standard documentation on the queue API, but it appears that if the queue item has completed (maybe also if it's currently being built?) it will have an executable node. One for my server looked like this:

"executable" : {
    "_class" : "org.jenkinsci.plugins.workflow.job.WorkflowRun",
    "number" : 10,
    "url" : "http://192.168.99.100:32769/job/configure/10/"
}

然后您可以 GET executable.url 中指定的URL的API.就我而言, GET http://192.168.99.100:32769/job/configure/10/api/json?pretty=true .从那里,您应该拥有所需的所有信息,包括当前是否正在构建内部版本,已花费/已花费了多长时间,结果等等.

You can then GET the API for the URL specified in executable.url. In my case, GET http://192.168.99.100:32769/job/configure/10/api/json?pretty=true. From there, you should have all the information you need, including whether or not the build is currently being built, how long the build took/has taken, the result, etc.

此外,如果您想要有关整个构建队列的信息,则可以 GET http://jenkins_srv:8080/queue/api/json?pretty = true

Also, if you want information on your entire build queue, you can GET http://jenkins_srv:8080/queue/api/json?pretty=true

这篇关于从队列ID获取Jenkins Job Build ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆