Get all pipeline Jobs in Jenkins Groovy Script
All pipeline jobs are instantces of org.jenkinsci.plugins.workflow.job.WorkflowJob
. So you can get names of all Pipeline jobs using the following function
@NonCPS
def getPipelineJobNames() {
Hudson.instance.getAllItems(org.jenkinsci.plugins.workflow.job.WorkflowJob)*.fullName
}
Then you can use it this way
//...
def jobs = getPipelineJobNames()
if (job_to_build in jobs) {
//....
}
try this syntax to get standard and pipeline jobs:
def jobs = Hudson.instance.getAllItems(hudson.model.Job.class)