Jenkins 2.0 is finally stable and has been promoted to the latest tag in the official Docker image. Developers can now take advantage of the new Pipelines feature and UI improvements. I’ve been a big fan of Jenkins since the Hudson days and use it on a daily basis - not only for continuous integration, but also for running cron jobs and miscellaneous tasks. However version 2 ships with a setup wizard that is enabled by default. This makes automated provisioning of the software more cumbersome. I’ll briefly demonstrate how I manage to work around this hurdle with a simple Docker image I’ve put together.

Note: In order to complete this tutorial you should have a working Docker installation available.

First, start by cloning my example repository:

$ git clone https://github.com/robmorgan/jenkins2-docker.git
$ cd jenkins2-docker

Next we should generate a new SSH keypair for use with the GitHub deploy keys feature. This is important if we want to work with private GitHub repositories:

$ make keygen

Be sure not to enter any passphrase as they don’t play nice with automated jobs!

My Docker image sets up a new Jenkins 2.x installation, installs a bunch of plugins and configures a job that runs some of the test suite from my open-source project Phinx.

To build my image, run the build command:

$ make build

Now to fire up the Jenkins instance, execute the run command:

$ make run

Open your web browser and visit your Docker host on port 8080:

$ open https://localhost:8080

You can click on the Phinx job and start a new build to see the Pipelines feature in action.

Take a look at the Dockerfile to see how I work around the setup wizard:

ENV JAVA_OPTS "-Djenkins.install.runSetupWizard=false"

I found the best way to automate the provisioning was to spin up a fresh instance, manually add your jobs and then copy the configuration files out of the container. This avoids fighting with the HTTP API and the built-in security model.

Rob Morgan

CTO based in Berlin, Germany. Creator of #Phinx, Australian, Startups, Technology, Travel.

robmorgan _rjm_


Published