Groovy to list all jobs

Article ID:226941767
1 minute readKnowledge base

Issue

  • Is there a way I can list all Jenkins jobs on a server?

Resolution

Go to Script Console under Manage Jenkins, this script will print the name of all jobs including jobs inside of a folder and the folders themselves:

Jenkins.instance.getAllItems(AbstractItem.class).each {
    println it.fullName + " - " + it.class
};

This script will print the name of all jobs including jobs inside of a folder, but not the folders themselves.

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

This script will recursively print the name of all jobs implementing the AbstractProject class, i.e. Freestyle and Maven jobs.

Jenkins.instance.getAllItems(AbstractProject.class).each {it ->
    println it.fullName;
}

This script will recursively print the name of all the Multibranch jobs.

Jenkins.instance.getAllItems(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject).each {it ->
    println it.fullName;
}

Tested product/plugin versions

  • CloudBees Jenkins Enterprise 2.235.2.3

  • CloudBees CI 2.235.2.3