This example, based on the gradle-build example, uses the Job DSL Plugin to deploy the job configuration programmatically.
Instead of copying over the config.xml file for the managed job, the job is defined in a groovy script using the provided DSL.
Check out the blog article for this example.
- When the docker image is built, the seed job and the dsl script are copied over to Jenkins home.
- When running the docker image, the startup script builds the seed job.
- The seed job runs the DSL script, programmatically creating the job 'an-example-of-github-project'.
.
├── jenkins-home
│ ├── init.groovy.d
│ │ └── startup.groovy # run the seed job
│ ├── jobs
│ │ └── seed # seed job definition (should be the only config.xml)
│ ├── dsl
│ │ └── managedJobs.groovy.override # dsl script to create the managed jobs
│ └── plugins.txt # job-dsl plugin was added
└── Dockerfile # copy over the dsl directory
./gradlew dockerBuild dockerRun
Build the docker image locally and start Jenkins at http://localhost:8080/
The Job DSL Plugin allows the programmatic creation of projects using a DSL. This method is preferred over managing the job config.xml file(s). The DSL is more compact and readable compared to the XML format. Since the DSL is executed as a groovy script, it allows runtime logic (docker run time) whereas the XML file is a static content (docker build time).
Hosted at ticketfly/jenkins-example-job-dsl
- Docker Version 1.10 or higher.