I'm trying to list the jenkins jobs per plugin is being utilized. I see there's a plugin in jenkins, https://github.com/jenkinsci/plugin-usage-plugin, which displays the plugins usage in the Jenkins UI. But how do i get the same output from the groovy script?

  • i've a jenkins master and i'm trying list the jobs or builds that are being utilized by a particular plugin. Ex: how many jobs are configured/used by maven plugin – Sachin Jan 26 at 21:31
  • i was trying to test these scripts, support.cloudbees.com/hc/en-us/articles/216351528. In a similar way i want to list all the jobs configured with a particular plugin. – Sachin Jan 26 at 21:31

They quick and dirty answer is to "Display jobs group by the build steps they use" as updated below.

import hudson.model.*
import hudson.tasks.*

//All the projects on which we can apply the getBuilders method
def allProjects = Jenkins.instance.allItems.findAll{ it instanceof Project }

//All the registered build steps in the current Jenkins Instance
def allSteps = Builder.all()

//Group the projects by the build steps used
def projectsGroupBySteps = allSteps.inject([:]){
   map, step ->
   map[step.clazz.name] = allProjects.findAll{it.builders.any{ 

    println "--- ($it.value.size) $it.key ---"
println ''

println 'Occcurences:'
println "--- ($it.value.size) $it.key ---"
    it.value.each {
        println it }
    println ''

Note that a job has multiple sections: builders, publishers and buildWrappers. Depending on what you are looking for, replace

[allSteps = Builder.all(), allProjects.findAll{it.builders.any ]
[allSteps = Publisher.all(), allProjects.findAll{it.publishers.any ]
[allSteps = BuildWrapper.all(), allProjects.findAll{it.buildWrappers.any ]

Plugins may also be involved in the SCM section and as properties (eg: hudson.plugins.buildblocker.BuildBlockerProperty, com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty)

Obviously, same limitations of plugin-usage apply: does not scan pipeline steps plugin usage or build steps nested within an org.jenkinsci.plugins.conditionalbuildstep

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.