简体   繁体   English

如何为远程API在Jenkins中触发的构建获取正确的构建号

[英]How to get the right build number for a build triggered in Jenkins by remote API

I am triggering builds with parameters in Jenkins using Python request to the http://jenkins:8080/view/projectAlpha/job/deploy_job_with_params/build and I don't get any queue or build numbers to identify my build. 我正在使用对http:// jenkins:8080 / view / projectAlpha / job / deploy_job_with_params / build的 Python请求在Jenkins中使用参数触发构建,但是我没有任何队列或构建号来标识我的构建。

According to Jenkins' /api page for the above url: 根据詹金斯的/ api页面获取上述网址:

"To programmatically schedule a new build, post to this URL (means the /build url - RaamEEIL). If the build has parameters, post to this URL (means the /buildWithParameters url - RaamEEIL) and provide the parameters as form data. Either way, the successful queueing will result in 201 status code with Location HTTP header pointing the URL of the item in the queue." “要以编程方式安排新的构建,请发布到此URL(表示/ build URL-RaamEEIL)。如果构建具有参数,请发布到此URL(表示/ buildWithParameters URL-RaamEEIL),并将参数作为表单数据提供。这样,成功的排队将导致201状态代码的位置HTTP标头指向队列中该项的URL。”

However, instead of getting the queue's url (eg http://jenkins:8080/queue/item/21038/api/json ) in the location header that returns when depploying the build, I get the url http://jenkins:8080/view/projectAlpha/job/deploy_job_with_params/ so basically I don't get any queue number or build number 但是,不是在部署时返回的位置标头中获取队列的URL(例如http:// jenkins:8080 / queue / item / 21038 / api / json ),而是获得URL http:// jenkins:8080 / view / projectAlpha / job / deploy_job_with_params /所以基本上我没有任何队列号或内部版本号

I read a suggestion for a workaround, to send an additional parameter with some id, which I can use to verify that the latest build is my build or use it to search through a list of builds until I find the correct build. 我阅读了有关解决方法的建议,以发送带有一些ID的附加参数,该参数可用于验证最新的版本是我的版本,或用于搜索整个版本列表,直到找到正确的版本。

Thanks. 谢谢。

Well, it turns out that I got things mixed up. 好吧,事实证明我把事情搞混了。 This seems to happen to many others, so here is some info. 这似乎发生在许多其他人身上,所以这里有一些信息。

/build url - returns location = the url of the job. / build url-返回位置=作业的url。 doesn't include info on your build 在您的构建中不包含信息

/buildWithParameters url - returns location = the url of the queue item for your build / buildWithParameters url-返回location =构建队列项的url

According to Daniel Beck's comment on https://issues.jenkins-ci.org/browse/JENKINS-30317 - 根据丹尼尔·贝克(Daniel Beck)对https://issues.jenkins-ci.org/browse/JENKINS-30317的评论-

(By "This" the author means the /build url) (通过“ This”(作者)表示/ build url)

That's the problem. 那就是问题所在。 This is not actually the API. 这实际上不是API。 As I wrote before, the API as documented uses /buildWithParameters for parameterized builds. 如我之前所写,所记录的API使用/ buildWithParameters进行参数化构建。 This is pretending to be a web browser. 假装是网络浏览器。

...because web browsers would get redirected to a blank 404 error page. ...因为网络浏览器将被重定向到空白的404错误页面。 Again, you're not actually using the API here, you're pretending to be a web browser. 同样,您实际上并没有在这里使用API​​,而是在假装是网络浏览器。

So, although the API page states you can request the /build url, if you want to get the queue item url for your build as the 'location' header, you must request the /buildWithParameters url. 因此,尽管API页面指出您可以请求/ build URL,但如果要获取构建的队列项URL作为“ location”标头,则必须请求/ buildWithParameters URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jenkins git触发构建不阻塞 - Jenkins git triggered build not blocking 如何通过python代码获取jenkins作业的内部版本号 - how to get build number for jenkins job via python code 如何在 shell 命令中发送 Jenkins 构建号作为参数,该命令将在构建结束后执行 - How to send Jenkins build number as parameter in shell command which will get executed after build ends “build_job() 得到了一个意外的关键字参数”当 jenkins 作业通过 jenkins API 触发时出错 - "build_job() got an unexpected keyword argument" Error when jenkins jobs triggered through jenkins API 如何使用 Python Jenkins API 在 Jenkins 中查找和查询特定构建 - How to find and query a specific build in Jenkins using the Python Jenkins API 如何通过推送到其他存储库来触发GitHub存储库的Jenkins构建? - How can I make a Jenkins build for a GitHub repository be triggered by a push to a different repository? 如何通过Jenkins REST API或Python设置构建描述? - How to set the build description via Jenkins REST API or Python? python - 如何从jenkins的特定构建中获取分支名称? - python - how to get branch name from a specific build from jenkins? 使用python获取jenkins中的当前内部版本号 - Getting current build number in jenkins using python Jenkins api4jenkins 下载最后一个构建作业控制台输出 - Jenkins api4jenkins download last build job console output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM