Lets create some Jenkins containers with docker-compose!
We will be using an existing configured Jenkins project which can be found here: https://github.com/modern-jenkins-ci/docker-jenkins
Lets take a look at the docker-compose file:
Lets take a look at the Jenkins master Dockerfile:
Lets build the images before we startup Jenkins. The docker-compose up command will build the images automatically but we have to ablity to build the images before we start them up.
Build & Start Master
docker-compose build jenkins-master
Jenkins master configuration as code
❯ tree -L 2 build/master ├── Dockerfile ├── init.groovy.d │ ├── adminuser.groovy │ ├── buildagent.groovy │ ├── credentials.groovy │ ├── csrf.groovy │ ├── githuborg.groovy │ ├── mastersettings.groovy │ └── slavemaster.groovy └── plugins.txt
By leveraging Jenkins Groovy Hook script processes https://wiki.jenkins.io/display/JENKINS/Groovy+Hook+Script we can pre-configure users, build build agents, credentials, etc. all in code. This give us the ability to control all the configuration with code and brings us one step closer to treating the Jenkins infrastructure as cattle not pets.
Navigate to the Jenkins UI here: https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/ to see the fully configured Jenkins instance. In this incarnation of the Jenkins setup we are not using the have preconfigured:
Build & Start Agent
We will need to create the build agent with the proper join token. The easiest way to do this is to login to Jenkins UI and navigate to this link:
Thank we will need to copy paste the join token as the environment variable
docker-compose build jenkins-agent
Lets look at the master's log file:
docker-compose logs -f jenkins-master
We created a fully configured Jenkins instance