There are more than a dozen Jenkins plug-ins for Docker. This blog post reviews the most popular and useful plugins available for Docker including the Docker Plugin, the Docker Pipeline Plugin, the Docker build step plugin and the CloudBees Docker Build and Publish plugin. You can install any plug-in from Home > Manage Jenkins > Manage Plugins > Available and then you can filter using the provided textbox.
a) The Docker Plugin is a plugin to “dynamically provision a slave, run a single build, then tear-down that slave”. The only drawback of this solution is that you need to the define a docker hosts in advance.
- The docker hosts are defined in the option: Manage Jenkins > Configure System > Cloud > Add new cloud > Docker as seen below.
- You can have multiple “Clouds” (the most important parameter is the container cap). Then you will need to setup the base image that will be used to spin-up new containers. The suggested image by the plugin author is “evarga/jenkins-slave”, but you can use any image as long as it has a JDK to build apps and Jenkins can connect to it.
- Once your Cloud is setup, you can create a free style project and add a docker build step as seen below.
- Last but not least, you can modify the project properties to commit and push a resulting image on the successful competition of the job as seen below.
b) Docker pipeline plug-in: if you feel more confortable with scripting (i.e.: with creating a Jenkins project of type pipeline) then this plugin allows you to write code to pull an image, create a container, installs packages into the image as seen in the code snippet below.
sh ‘mvn -B clean install’
c) Docker build step: this plugin adds a plethora of docker commands options as seen in the image below. This options simply eliminates the need to write a script to execute the same commands in a manual way.
d) CloudBees Docker Build and Publish plugin: this is a simple plugin to access a docker host to build and publish a docker image (this is very similar to the Docker Plugin -step 7-). This plugin needs a Dockerfile.
This build step is very similar to the “Docker Plugin” build step seen below:
In summary: the “Docker build step plugin” and the “CloudBees Docker Build and Publish” plugin don’t add much value and this functionality is included in the “Docker Plugin”.
The “Docker Plugin” allows you to setup multiple docker hosts and it is more flexible in terms of distributing the workload and setting up the host/image parameters. The “Docker Pipeline Plugin” is very flexible and ideal for customizing your build. It would be cool to have a mix of these two plug-ins.
Javier Andrés Cáceres Alvis
Microsoft Most Valuable Professional – MVP
Intel Black Belt Software Developer