How to generate jenkins job based Daily report
To create specific job based daily report with all parameter with user name and output result , and mailed report
for some R&D i use
import hudson.tasks.Shell
println Jenkins.instance.getAllItems(FreeStyleProject.class).findAll { job -> job.builders.findAll { it in Shell } && job.builders.findAll { it in Shell }.collect { shell -> shell.command}}
it give me shell output but i m unable to get other content like parameters, user who run it etc
I also tried few jenkins plugins but i m not able to get what i required or i just missed some plugins
-
It's not clear what kind of report you are trying to generate and why. Could you clarify?
The script that you quoted is printing all the scripts in the `Execute shell` builds steps of the Freestyle Projects.
0 -
we not using jenkins only for code build and deploye or pipeline
we also use jenkins for extracting data from logs file or run DB query (for non-technical people who don't have idea how to execute query or how to run command on shell for data extraction)
but end of day we must required a some kind report where it mention of which user run job with what build parameters for accountability and auditing purpose on daily basis
so i want to do
1. create new scheduled job which run groovy scripts
2.filter disered job name from FreeStyleProject which having current date of execution and get user name build parameter and shell output and append string in html file and mailed to desired person
the issue is here is i m not geeting all thing after single job iteration mention above scripts and also not able to understand grrovy library method for getting appropriate data
So please help me
0 -
The info you are looking for is available. I think there are multiple ways to accomplish this, but I think something like this will help you get started:
Jenkins.instance.getAllItems(Job.class).getBuilds()
...and then you can loop each of the builds.However, I find that the Jenkins object model is not extremely straightforward. The class structure often requires you to drill down into a variety of aspects in order to get all of the info that you are looking for. For example, once you have the job, you need to get the runs, and for a given run you need to get the cause before you can identify the user who triggered it. The CloudBees methods/etc. can be a bit challenging to decipher since they are not published but for the non-proprietary items you can find a good bit within the Jenkins javadocs...and there are often multiple paths which will lead to a solution. I usually end up trying a few before I get it right.
Some relevant links that hopefully will get you set on the right path:
https://javadoc.jenkins.io/hudson/model/Job.html
https://javadoc.jenkins.io/hudson/model/AbstractItem.html#getFullName--
https://javadoc.jenkins.io/hudson/model/AbstractBuild.html#getBuildVariables--
https://javadoc.jenkins.io/hudson/model/Run.html#result
https://javadoc.jenkins.io/hudson/model/Run.html#timestamp
https://javadoc.jenkins.io/hudson/model/Cause.UserIdCause.html0
Please sign in to leave a comment.
Comments
3 comments