Skip to content

Instantly share code, notes, and snippets.

@ThabetAmer
Created January 18, 2020 08:03
Show Gist options
  • Save ThabetAmer/e36584b7a64b61b4619fb96dd0055fab to your computer and use it in GitHub Desktop.
Save ThabetAmer/e36584b7a64b61b4619fb96dd0055fab to your computer and use it in GitHub Desktop.
Groovy/Jenkins function to list all enabled Jenkins jobs by name.
#!/usr/bin/env groovy
/**
* Lists all enabled Jenkins jobs by name.
* @author [email protected]
* @since Jenkins 2.204.1
* @param Bool includeDisabled to include also disabled jobs, default false (No).
* @return String array of jenkins jobs names
*
*/
import hudson.model.AbstractModelObject
def getAllJobs(includeDisabled = false) {
return jenkins.model.Jenkins.instance.getAllItems(hudson.model.AbstractItem.class).
findAll{includeDisabled ? it : it.disabled==false}.collect{it.fullName}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment