How do I get a list of jobs with longest build tim

2019-02-22 06:17发布

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.

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".

This feels quite cumbersome, does anyone know a better solution using Jenkins API or Groovy script console?

Thanks

2条回答
Deceive 欺骗
2楼-- · 2019-02-22 07:03

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]

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.

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.

查看更多
放我归山
3楼-- · 2019-02-22 07:06
登录 后发表回答