Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a list of jobs with longest build time in 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.

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

like image 795
Jifeng Zhang Avatar asked Sep 03 '14 16:09

Jifeng Zhang


2 Answers

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.

like image 59
Dave Bacher Avatar answered Sep 21 '22 22:09

Dave Bacher


How about using plugins?

Check this out:
https://wiki.jenkins-ci.org/display/JENKINS/build-metrics-plugin

There are few others too which you can try depending on how much customization/features you want to do/display:
https://wiki.jenkins-ci.org/display/JENKINS/Global+Build+Stats+Plugin - This is quite extensive https://wiki.jenkins-ci.org/display/JENKINS/Project+Statistics+Plugin https://wiki.jenkins-ci.org/display/JENKINS/eXtreme+Feedback+Panel+Plugin

like image 35
Technext Avatar answered Sep 23 '22 22:09

Technext