Get overview for jobs and build-durations in your Jenkins

Someday your boss will ask you to get a list of all jobs and their build-durations in your Jenkins… as often as quick as possible 😉

Just use the following piece of Groovy-code in the Jenkins-console and lay back.

// show duration of all jenkins-jobs (that had a stable build)
// ------------------------
import  java.util.concurrent.TimeUnit

for(item in Hudson.instance.items) {
	lastStableBuild = item.getLastStableBuild();
 	if (lastStableBuild != null){
               	durationMillis = lastStableBuild.getDuration() ;         
        	duration = String.format("%d min, %d sec", 
   			TimeUnit.MILLISECONDS.toSeconds(durationMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(durationMillis))
       	 	name = item.getName();
		printf("%s (%s)\n", name, duration);

Of course you can also get this overview in a more machine-friendly csv-format, so your Excel or Calc can read it. just replace the printf-line with

   printf("%s;%s\n", name, duration);