Home > Software engineering >  Export all jobs from jenkins including run history
Export all jobs from jenkins including run history

Time:12-25

Ideally I need a script that outputs the following information in a CSV format that's easy to import into Excel:

job name,number of times run in last year,number of times run overall,last run status

For that job, output no individual run details.

Tried this on my Jenkins: List Jenkins job build detials for last one year along with the user who triggered the build.

but got an error:

java.lang.NullPointerException: Cannot invoke method getShortDescription() on null object
    at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

Any idea what in the Groovy needs changing? or is there a better solution?

Thanks all!

CodePudding user response:

Thanks to @daggett and @ian . Both worked.

I went with IANS : def jobNamePattern ='.'   // adjust to folder/job regex as needed def daysBack = 365   // adjust to how many days back to report on def timeToDays = 2460601000  // converts msec to daysprintln "Job Name: ( # builds: last ${daysBack} days / overall )  Last Status\n   Number | Trigger | Status | Date | Duration\n"Jenkins.instance.allItems.findAll() {   it instanceof Job && it.fullName.matches(jobNamePattern) }.each { job ->   builds = job.getBuilds().byTimestamp(System.currentTimeMillis() - daysBack*timeToDays, System.currentTimeMillis())   println job.fullName ' ( ' builds.size() ' / ' job.builds.size() ' )  ' job.getLastBuild()?.result      // individual build details   builds.each { build ->     println '   ' build.number ' | ' build.getCauses()[0]?.getShortDescription() ' | ' build.result ' | ' build.getTimestampString2() ' | ' build.getDurationString()   } } return

  • Related