Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks such as building, testing, and deploying software.
This project builds a Docker image that contains a fully configured Jenkins. Often, Jenkins is configured by hand. This has several problems:
- Over time, it becomes hard to understand how it was configured and why.
- Testing out configuration changes is difficult and often happens in production.
- The configuration must be backed up in case the machine the where the configuration is located crashes.
By completely automating the configuration of Jenkins:
- The configuration is completely traceable and changes to the configuration can be tracked over time.
- Configuration changes can be developed and tested locally.
- A new instance of Jenkins spun up and configured within minutes.
docker run \
--name auto-jenkins \
--publish 8080:8080 \
--detach \
--restart always \
depositsolutions/jenkins-automationIn its default state, auto-jenkins has a single job called seed-job that creates the other jobs listed in the file
job.groovy.override. Simply run the seed job to initialize the other jobs.
Once it is completed, you should see all jobs listed on auto-jenkins' dashboard. auto-jenkins should be ready to be used: run your newly added job and ensure Jenkins is behaving correctly.
See https://github.com/jenkinsci/docker#usage for more information and options.
All configuration is done using Groovy scripts located in src/main/resources/docker/init.groovy.d. Use the
Jenkins Javadoc as a reference.
Some Groovy scripts use environment variables to make it easy to configure the container. The following table lists the most common environment variables.
| Environment variable | Description |
|---|---|
| JENKINS_ADMIN_EMAIL | The admin's e-mail address |
| JENKINS_BASE_URL | The base URL of Jenkins |
| JENKINS_MASTER_EXECUTORS | The number of executors for the master |
| JENKINS_SLAVEPORT | Port for slaves to connect to |
| SMTP_HOST | SMTP server hostname |
| SMTP_PORT | SMTP server port number |
- Clone the repository
git clone git@github.com:depositsolutions/jenkins-automation.git
- Locate the file
job.groovy.overrideand add your repository to the list ofprojectDefinitions.
Just modify the file plugins.txt file. See also https://github.com/jenkinsci/docker#preinstalling-plugins for more
information.
mvn clean install -Plocal