Build Duration Information

301 views
Skip to first unread message

Eric Naitove

unread,
Sep 30, 2015, 2:02:47 PM9/30/15
to Jenkins Users
I at some time via Groovy or the API obtained a list of all my jabos and the run tines as follows

GwInt202DeployTomcatCc 8 min 54 sec - #1352

It was a large list that I cleaned up grabbing the last build (meaning the entry above had several hundred lines.  I kept the last one in an Excel spreadsheet)

Any help would be appreciated

Victor Martinez

unread,
Sep 30, 2015, 2:19:53 PM9/30/15
to Jenkins Users
Hi Eric,

 Can you explain further? 

Cheers

Eric Naitove

unread,
Sep 30, 2015, 3:35:37 PM9/30/15
to Jenkins Users
Using something like

/api/xml?tree=jobs[name,url]&pretty=true OR
/api/xml?tree=jobs[name,builds[number,actions[parameters[name,value]]]]&pretty=true ETC.

Can I get an out put of jobs with lastBuild duration in HOURS/MINUTES

I can convert in Excel BUT it doesn't match with Jenkins

AND management being management..... :)

Benjamin Lau

unread,
Sep 30, 2015, 4:42:29 PM9/30/15
to Jenkins Users
This formula isn't perfect but it'll convert a jenkins duration into a
human readable time[1].
=IF(INT(1/86400000*A3)=0, "",INT(1/86400000*A3) &" day, ") &
IF(INT(MOD(A3,86400000)/3600000)=0,"", INT(MOD(A3,86400000)/3600000) &
" hr, ") & IF(INT(MOD(A3,3600000)/60000)=0,"",
INT(MOD(A3,3600000)/60000) &" min, ") &
IF(INT(MOD(A3,60000)/1000)=0,"", INT(MOD(A3,60000)/1000) &" sec")

This might need some formatting improvements... and maybe some
additional logic for whether to show different fields. But it's
probably a good starting point.

Cheers,
Ben
[1] Adapted from this post I found:
http://www.mrexcel.com/forum/excel-questions/73152-converting-seconds-hours-minutes-seconds.html#post351958
and then adjusted to work from miliseconds instead of seconds and to
allow for conditional display of the fields (eg if there are no
hours... the field isn't shown)
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-use...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/309d1ec5-7b5b-47a7-bc9e-c133fae7916d%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Victor Martinez

unread,
Sep 30, 2015, 5:37:09 PM9/30/15
to Jenkins Users
Hi Eric,

 I recommend you to use another approach via Groovy API then you can run your script easily via your jenkins script console url: /script (https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console)

 Important javadoc references:

 Your script might be something like

 
import jenkins.model.*

println "JOB_NAME,BUILD_ID,DURATION(ms),DATE"
Jenkins.instance?.items.each { job ->
  if ( job.getLastBuild() != null ) {
    println "${job.name},${job.getLastBuild().getNumber()},${job.getLastBuild().getDuration()},${job.getLastBuild().getTime()}"
  } else {
    println "${job.name},na,na,na"
  }
                
}
println "done"


I hope it helps

Cheers 
Reply all
Reply to author
Forward
0 new messages