4

I have a Jenkins server that builds/tests about 50 projects. Unfortunately, some of these builds fail, but I don't have a good way to measure whether build failures are increasing or decreasing in frequency over time.

What I'd like is something along these lines:

  • A report that shows me, over the course of a month, how many jobs were unstable/failed
  • A report that says "X Days without a broken build" (kind of like at construction sites)
  • A "Red/Green calendar", that would show on a per-day basis whether any builds were broken

I didn't see any plugins that visualized data in any of these ways, but I'm willing to scrape the Jenkins logs to get the information. Is there a better way to see data similar to this?

matthewsteele
  • 1,797
  • 1
  • 15
  • 31

4 Answers4

4

I think this work pretty decent using the API. You can get all jobs from your view, then go into the job details and get the build numbers and build date. With those build numbers you can get the corresponding status. You would have to do some coding to collect and display the data, but this would be a possible way.

Another possibility would be using a Groovy script over the console in Manage Jenkins. I do not have much experience working with that feature though, but as you have access to the internal representation it should be pretty easy to get some data out of there.

Finally, the optimal solution would be to write a plugin that does the work, but this is of course also the solution that requires the most effort and know-how.

pushy
  • 9,535
  • 5
  • 26
  • 45
3

As @pushy mentions, the Groovy script console is a good tool to use for these types of statistics gathering. You can use the groovy script in the remote API as well. Here is a starting point for gathering information from all jobs matching a pattern.

def jobPattern='pattern'
Hudson.instance.getItems(Project).each {project ->
  def results = [:]
  if (project.name.contains(jobPattern)) {
    results."$project.name" = [SUCCESS:0,UNSTABLE:0,FAILURE:0,ABORTED:0]
    def build = project.getLastBuild()
    while (build){
      //println "$project.name;$build.id;$build.result"
      results."$project.name"."$build.result" = results."$project.name"."$build.result" +1
      build=build.getPreviousBuild()
    }
  }
  results.each{name,map->
    map.each{result,count->
      println "$name : $result = $count"
    }
  }
}
"Done"

Use this as a start and modify according to your specific requirements.

Jocce Nilsson
  • 1,658
  • 14
  • 28
  • I've updated the by using the latest Java API, detail can be found in https://marslo.github.io/ibook/jenkins/script/script.html#get-build-status . in case any one need it. – Marslo Nov 09 '20 at 15:06
  • Thats great @Marslo! – Jocce Nilsson Nov 10 '20 at 17:57
  • Thanks @Marslo! what about total number of builds over time? – Abdennour TOUMI May 06 '21 at 01:57
  • @AbdennourTOUMI, I suppose you may want to try [get builds result and percentage within certain start-end time](https://marslo.github.io/ibook/jenkins/script/build.html#get-builds-result-and-percentage-within-certain-start-end-time), which will list both status percentage and also associated build numbers. btw, setup `PARAM` to empty will ignore matches params (`final Map PARAM = [ : ]`), or get more sample jenkins scripts from [jobs & builds](https://marslo.github.io/ibook/jenkins/script/build.html#build-results) – Marslo May 07 '21 at 11:35
3

The Global Build Stats plugin might provide the reporting you're looking for.

(And if you already considered this plugin, I'm curious what problems you ran into.)

Dave Bacher
  • 15,652
  • 3
  • 63
  • 86
0

Try build metric plugin along with Global Build Stat plugin.

abhinav
  • 411
  • 6
  • 7