如何获得詹金斯(Jenkins)最长建造时间的工作清单 [英] How do I get a list of jobs with longest build time in Jenkins
问题描述
我需要针对我们的Jenkins构建集群生成每周报告.报告之一是显示具有最长构建时间的作业列表.
I need to generate a weekly report on our Jenkins build cluster. One of the reports is to display a list of jobs that have the longest build time.
我能想到的解决方案是解析每个从属服务器(也是主服务器)上的构建历史"页面,对于作业的每个构建,都解析该构建页面并查找在从属服务器上-x min x sec- xx".
The solution I can come up with is to parse the "Build history" page on each slave (also master) and for each build of a job, parse the build page and look for "Took x min x sec on slave-xx".
这很麻烦,有人知道使用Jenkins API或Groovy脚本控制台有更好的解决方案吗?
This feels quite cumbersome, does anyone know a better solution using Jenkins API or Groovy script console?
谢谢
推荐答案
您可以通过Jenkins API获取报告的构建数据.对于给定的工作,您可以 检索带有持续时间信息的构建列表,例如:
You can get the build data for your report through the Jenkins API. For a given job, you can retrieve the list of builds with duration information using something like:
http://jenkins:8080/job/my-job/api/json?tree=builds[id,number,duration,timestamp,builtOn]
要查看给定作业的所有API可用的构建数据的列表:
To see a list of all the API-available build data for a given job:
http://jenkins:8080/job/my-job/api/json?tree=builds[*]
一旦您有一个查询,该查询将检索您需要的工作信息 您的报告,应该很容易遍历工作.
Once you have a query that retrieves the job information that you need for your report, it should be straightforward to loop over the jobs.
大多数Jenkins页面的底部都有一个指向REST API的链接,该链接描述了有关访问该页面的API的一些信息,例如http://jenkins:8080/job/my-job/api
.
Most Jenkins pages have a link at the bottom to the REST API that describes a bit about accessing the API for that page, e.g. http://jenkins:8080/job/my-job/api
.
这篇关于如何获得詹金斯(Jenkins)最长建造时间的工作清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!