Skip to content
wiki[bot] edited this page Aug 27, 2024 · 6 revisions

Support for Configuration as Code Plugin

See Configuration as Code for an introduction to managing global Jenkins settings as code.

The Job DSL plugin provides an extension to run Job DSL scripts when configuring Jenkins using Configuration as Code. These scripts can be used to create an initial seed job.

To get started, add a root element called jobs. The given script will be executed by the Job DSL plugin.

jobs:
  - script: >
      multibranchPipelineJob('configuration-as-code') {
          branchSources {
              git {
                  id = 'configuration-as-code'
                  remote('https://github.com/jenkinsci/configuration-as-code-plugin.git')
              }
          }
      }

You can also fetch Job DSL scripts from a file or URL.

jobs:
  - file: ./jobdsl/job.groovy

Note that relative paths are resolved relative to the current working directory of the Jenkins server, which may not necessarily be the same as $JENKINS_HOME, depending on how your server was started.

jobs:
  - url: https://example.acme.org/job-dsl/testjob.groovy

You can reference multiple scripts, files, and URLs.

jobs:
  - script: >
      job('testJob1') {
          scm {
              git('git://github.com/quidryan/aws-sdk-test.git')
          }
          triggers {
              scm('H/15 * * * *')
          }
          steps {
              maven('-e clean test')
          }
      }

  - script: >
      job('testJob2') {
          scm {
              git('git://github.com/quidryan/aws-sdk-test.git')
          }
          triggers {
              scm('H/15 * * * *')
          }
          steps {
              maven('-e clean test')
          }
      }

  - file: ./jobdsl/job1.groovy
  - file: ./jobdsl/job2.groovy

You can pass values from the YAML file to the Job DSL script.

jobs:
  - providedEnv:
      SUPERHERO: 'Midnighter'
  - file: ./jobdsl/job.groovy
//job.groovy
job('awesome-job') {
    description("favorite job of ${SUPERHERO}")
}