Jenkins – Invoke Job DSL from Jenkins Pipeline

Jenkinsjenkins-job-dsljenkins-pipeline

I need to trigger Jenkins Job DSL from pipeline (specifically, i need to mimic 'read definition file from workspace' behavior), but the job dsl plugin isn't yet on pipeline steps list. How can i achieve that?

Best Answer

The Job DSL wiki shows how to run Job DSL as a Pipeline step: https://github.com/jenkinsci/job-dsl-plugin/wiki/User-Power-Moves#use-job-dsl-in-pipeline-scripts

node {
  jobDsl scriptText: 'job("example-2")'

  jobDsl targets: ['jobs/projectA/*.groovy', 'jobs/common.groovy'].join('\n'),
       removedJobAction: 'DELETE',
       removedViewAction: 'DELETE',
       lookupStrategy: 'SEED_JOB',
       additionalClasspath: ['libA.jar', 'libB.jar'].join('\n')
}