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:
Here is my Script Collection:
https://github.com/rajendrapenumalli/jenkins-scripts

Other Useful links:
https://jenkins.io/doc/book/managing/script-approval/
https://pghalliday.com/jenkins/groovy/sonar/chef/configuration/management/2014/09/21/some-useful-jenkins-groovy-scripts.html


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

*Thanks and Regards,*



*Rajendra Prasad Reddy PenumalliSr. Engineer in Testing.Mobile:9008566233*


On Mon, 12 Nov 2018 at 03:46, trupti bhatt <[email protected]> wrote:

> 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
>
>
> On Thursday, November 8, 2018 at 3:49:14 PM UTC+5:30, rajendraprasad reddy
> wrote:
>>
>> 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:
>>
>>
>> https://github.com/cloudbees/jenkins-scripts/blob/master/get-build-information.groovy
>>
>> You need to use groovy plugin and it looks like below link.
>>
>>
>> https://www.google.com/search?safe=active&q=jenkins+groovy+script+examples&sa=X&ved=2ahUKEwj-weOYx8TeAhXEtI8KHbCMABQQ1QIoA3oECAoQBA&biw=412&bih=660&dpr=2.63#imgrc=qnNClrZNVTUKnM
>> :
>>
>> I know I didn't have you full solution but I hope this will give some
>> direction for to implement your requirement.
>>
>> Thanks
>> Rajendra
>>
>>
>>
>> On Tue, 6 Nov, 2018, 15:41 trupti bhatt <[email protected] wrote:
>>
>>> I want to get the jenkins report as in this template:
>>>
>>> [image: enter image description here]
>>> <https://i.stack.imgur.com/JLX16.png>
>>>
>>> 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
>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/jenkinsci-users/291de8a3-6bf5-4d5e-ae15-625044d11aaa%40googlegroups.com
>>> <https://groups.google.com/d/msgid/jenkinsci-users/291de8a3-6bf5-4d5e-ae15-625044d11aaa%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/a10ec883-07bf-4bcd-919c-410bc0abaa00%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-users/a10ec883-07bf-4bcd-919c-410bc0abaa00%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAMrg02RQ%3DszhQXU4XneX9h5%3DiijYFnkr53d9fnoZuGwFxpnQsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to