使用 Hudson/Jenkins API 确定给定作业当前是否正在运行
是否有 API 可以确定给定作业当前是否正在运行?
理想情况下,我还希望能够确定其估计完成百分比并获取 SVN 修订号和提交评论的详细信息!
编辑:
我找到了答案。 http://host/job/project/lastBuild/api/
几乎拥有我需要的所有内容!如果您开始手动构建,它不会告诉您 SCM 变更集,但这是有道理的。不过它仍然会告诉您最新的 SCM 版本,所以这很好。总而言之,对于我现在的目的来说已经足够了。
Is there an API to determine whether a given job is currently running or not?
Ideally, I'd also like to be able to determine its estimated % complete and get the details of the SVN revision number and commit comment too!
EDIT:
I found the answer. http://host/job/project/lastBuild/api/
has almost all of what I need in it somewhere! If you kick off a manual build, it won't tell you the SCM changesets, but that makes sense. It does still tell you the latest SCM revision though, so that's good. All in all, good enough for my purposes right now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正如 gareth_bowles 和 Sagar 所说,使用 Jenkins API 是了解的方法。
如果将深度设置为 1,您将看到您要查找的内容:
您将看到有一个
标记来判断该构建是否正在运行As gareth_bowles and Sagar said, using the Jenkins API is the way to know.
If you put the depth to 1, you will see what you're looking for:
You will see there's a
<building>
tag to tell if that build is running我正在使用 Groovy 插件,并作为系统运行以下代码片段:
它的工作方式就像一个魅力。
I'm using the Groovy plug-in, and run the following snippet as system:
It works like a charm.
如果您转到职位页面,并将“api”添加到 URL 末尾,您将获得有关使用 API 的信息。
有关使用 Jenkins API 的更多信息:
If you go to your job's page, and add "api" to the end of the URL, you'll get information on using the API.
More information on using the Jenkins API:
如果您习惯于深入研究 Jenkins Java API,则可以编写系统 Groovy 脚本来获取此数据。 Job 类 是起点。
If you're comfortable with digging through the Jenkins Java API, you could write a system Groovy script to get this data. The Job class is the place to start.
如构建的
/api
页面(“访问渐进式控制台输出”一章)所述,您可以通过调用使用 GET 请求轮询控制台输出。 /lastBuild/logText/progressiveText
。引用 API 文档:,就这样。您可以通过简单地在浏览器中调用相应的 URL,然后使用浏览器的开发人员工具(通常通过按 F12 访问)检查响应标头来测试此行为。在Firefox中,相应的选项卡称为“网络分析”(假设我的翻译是正确的,我的浏览器没有设置为英语)。在 Chrome 中,导航至“网络”选项卡。
这个答案基于 Jenkins 版本 2.176.3。
As stated on the
/api
page of your build (chapter "Accessing Progressive Console Output"), you can poll the console output with a GET request by calling<url-to-job>/lastBuild/logText/progressiveText
. To quote the API doc:And there you go. You can test this behaviour by simply calling the respective URL in your browser and then inspecting the response headers with your browser's developer tools (usually accessed by pressing F12). In Firefox, the respective tab is called "network analysis" (assuming my translation is correct, my browser is not set to English). In Chrome, navigate to the "Network" tab.
This answer is based on Jenkins version 2.176.3.
还可以查看颜色属性。我知道这不是想要的方式。但也许有人可以利用它。
通过“/job/api/xml”获取概述 xml,然后检查“anim”的颜色属性。
It is also possible to look at the color attribute. I know it is not the wanted way. But maybe someone can make use of it.
get the overview xml via "/job/api/xml" and then check the color attribute for "anim".