Jenkins is an automation server that can be used for Continuous Integration and Continuous Delivery.
Docker is a platform for running applications in containers. The Mantra that says if you do something more than one time than you must automate it.
Sometimes there is so much to do that this simple mantra is forgotten. I just started to work with Jenkins Job Builder (JJB) and then it occurred to me that I’ll probably move to other things and then forget all about it. So I figured one way to do it is to build a Docker image. It’s probably an overkill for such a task that probably can be done by running a script to build a virtualenv but nevertheless an enjoyable way to do it ..
Assuming there is a directory jobs that holds 2 files: myjenkins.conf and myjob.yml
myjenkins.conf is a JJB configuration file (Refer to http://docs.openstack.org/infra/jenkins-job-builder/execution.html# )
myjob.yml is a YAML file that describes one or more jobs.
Create a directory called jjb
In the directory jjb create a file named Dockerfile with the following content:
Register to Dockerhub at https://hub.docker.com/ if you don’t already have a user Login to Docker hub, build and push the image to Docker hub (replace user with your user name)
Check your job definition
–rm flag is telling Docker to automatically clean up the container and remove the file system when the container exits
–volume is for defining a mount point in the container- in our case it will mount our current directory as /opt/jenkins-job in the container
–workdir is the default directory the container will move to when it starts
user/jjb is the image name (you have to replace user with your own name)
jenkins-job is the JJB program and the rest is it’s argumentsUpload(/Update) the job
Once you have your image at Docker hub you can run the JJB commands without building it first.
Note: You can use my image instead of building your own - replace the user with itzikb.
You may encounter permission denied issue when accessing the volumes. You may either choose to disable SELinux temporarily by running
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Your probably need to start the docker daemon by running:
$ sudo systemctl start docker