Skip to content

Instantly share code, notes, and snippets.

@ThabetAmer
Created January 18, 2020 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 thabet.amer@gmail.com
* @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