Groovy syntax to retrieve a job's type
AnsweredI've seen and used the plugins to get the job types of a job on Jenkins but I'd like to write a groovy script to display all existing jobs and their type. I know that the plugins show some job types as unknown. The plugins have a way to grab the job type, is there a groovy way to do it?
-
Hi Brandon,
You can run this script from the Jenkins script console. This is a very basic approach, but I am sure that you can refine it.
```
Jenkins.instance.getAllItems(Job).each{job -> job.isBuildable()
if (job.isBuildable()!=null)
println job.name +"--->"+ job.class
}```
Best regards,
1 -
Thanks @Manuel, that works amazingly.
Now i'm trying to filter out certain classes so i can find out all the classes that exist in my results. For some reason my statement:
if(!(job instanceof MavenModule))
still does not filter out class 'hudson.maven.MavenModule' results
0 -
I think it's because MavenModule is not a job, but a plugin?
0 -
You will need to provide the FQN: hudson.maven.MavenModuleSet
That should work. If you review the output from the execution of the first script that would help you use the correct class name for the jobs that you want to work with.
Hope that helps.
1 -
Thank you @Manuel. That works.
0 -
In case this question gets searched for again,
job.getClass().simpleName
This would show only the project class type name without the library information.
For example, you would see this if anyone would need to:
test--->FreeStyleProject
0
Please sign in to leave a comment.
Comments
6 comments