Jenkins dashboard report with customization

201 views
Skip to first unread message

trupti bhatt

unread,
Nov 6, 2018, 5:11:06 AM11/6/18
to Jenkins Users

I want to get the jenkins report as in this template:

enter image description here

so which plugin will help me to get such kind of report?

I have tried multiple plugins, but no luck. I have tried test analyzer report, dashboard view and jenkins matrix and trends plugin. 


I think Groovy scripts may help. can anyone help me on it? 




Thank you,

Trupti Bhatt

RAJENDRA PRASAD

unread,
Nov 8, 2018, 5:19:14 AM11/8/18
to jenkins...@googlegroups.com
Hi Tripti,
You are correct there is no  plugin that can help you to create a custom dashboard specified by you.

All you need to write a groovy script to  access Jenkins job history and prepare  report according to your need


First get list of jobs via groovy script:

Jenkins.instance.getAllItems(Job.class).each{ 
  println it.name + " - " + it.class
  }

Next get each job and get build status :
Following link has  script that can help you in that:


You need to use groovy plugin and it looks like below link.


I know I didn't have you full solution but I hope this will give some direction for to implement your requirement.

Thanks
Rajendra



--
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/291de8a3-6bf5-4d5e-ae15-625044d11aaa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

trupti bhatt

unread,
Nov 12, 2018, 6:46:25 AM11/12/18
to Jenkins Users
Thanks Rajendra.

I have tried following code: but throwing me compilation error:

Jenkins.instance.getAllItems(Job.class).each{ 
  println it.name + " - " + it.class

 def jobBuilds=it.getBuilds()
//for each of such jobs we can get all the builds (or you can limit the number at your convenience)
    jobBuilds.each { build ->
      def runningSince = groovy.time.TimeCategory.minus( new Date(), build.getTime() )
      def currentStatus = build.buildStatusSummary.message
 def cause = build.getCauses()[0]

 println "Build: ${build} | Since: ${runningSince} | Status: ${currentStatus} | Cause: ${cause}" 
 // You can get all the information available for build parameters.
      def parameters = build.getAction(ParametersAction)?.parameters
      parameters.each {
        println "Type: ${it.class} Name: ${it.name}, Value: ${it.dump()}" 
}
}
  }


Error Is :
ERROR: Build step failed with exception
groovy.lang.MissingPropertyException: No such property: Jenkins for class: Script1
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script1.run(Script1.groovy:1)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:343)
at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95)
at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1815)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Build step 'Execute system Groovy script' marked build as failure

RAJENDRA PRASAD

unread,
Nov 16, 2018, 8:09:11 PM11/16/18
to jenkins...@googlegroups.com
Hi Trupti Bhatt,
Was damn busy , not able to respond for you mail.
Please add import statement on top of your script , it must work,



import jenkins.model.*

Jenkins.instance.getAllItems(Job.class).each{ 
  println it.name + " - " + it.class

 def jobBuilds=it.getBuilds()
//for each of such jobs we can get all the builds (or you can limit the number at your convenience)
    jobBuilds.each { build ->
      def runningSince = groovy.time.TimeCategory.minus( new Date(), build.getTime() )
      def currentStatus = build.buildStatusSummary.message
 def cause = build.getCauses()[0]

 println "Build: ${build} | Since: ${runningSince} | Status: ${currentStatus} | Cause: ${cause}" 
 // You can get all the information available for build parameters.
      def parameters = build.getAction(ParametersAction)?.parameters
      parameters.each {
        println "Type: ${it.class} Name: ${it.name}, Value: ${it.dump()}" 
}
}
  }

Other Important links that will help you are:

Other Useful links:


dont forget to send me you solution (after removing any sensitive data ;))

Thanks and Regards,
Rajendra Prasad Reddy Penumalli
Sr. Engineer in Testing.
Mobile:9008566233


RAJENDRA PRASAD

unread,
Nov 22, 2018, 2:27:14 AM11/22/18
to jenkins...@googlegroups.com
Few more info i would like to add:

Unlike the Jenkins Script Console, Jenkins-related libraries are not auto-imported, so make sure you import the following into your scripts:

import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*


Thanks and Regards,
Rajendra Prasad Reddy Penumalli
Sr. Engineer in Testing.
Mobile:9008566233

Reply all
Reply to author
Forward
0 new messages