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.

  1. The docker hosts are defined in the option: Manage Jenkins > Configure System > Cloud > Add new cloud > Docker as seen below.
  2. 0-add-cloud1-configure-docker-hosts
  3. 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.
  4. Once your Cloud is setup,  you can create a free style project and add a docker build step as seen below.
  5. 2-use-a-cloud
  6. 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.
  7. 3-push on job completition.png

 

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.

docker.image(‘maven:3.3.3-jdk-8’).inside {
  git ‘…your-sources…’
  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.

4-adds-docker-commands

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.

5-docker-build-and-publish

This build step is very similar to the “Docker Plugin” build step seen below:

6-docker-build-dynamic

 

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.

Thanks,

Javier Andrés Cáceres Alvis

Microsoft Most Valuable Professional – MVP

Intel Black Belt Software Developer