CI as Code Part I: Stateless Jenkins Deployments Using Docker

Currently co-authoring a book on Docker:

Get 39% off with the code 39miell2


I don’t know about you, but I’ve always been uncomfortable with Jenkins’ apparent statefulness. You set up your Jenkins server, configure it exactly as you want it, then DON’T TOUCH IT.

For an industry apparently obsessed with ‘infrastructure/environments/whatever as code’ this is an unhappy state of affairs.

I’d set up a few Jenkins servers, thrown some away, re-set them up, and it always seemed a wasteful process, fraught with forgetfulness.

Fortunately I now have a solution. With a combination of Docker, Python’s Jenkins API modules, the Jenkins job builder Python module, and some orchestration using docker-compose, I can reproduce my Jenkins state at will from code and run it in isolated environments, improving in iterable, track-able steps.

Here’s a video of it running:

This example sets up:

  • a vanilla Jenkins instance via a Docker container
  • a simple slave node
  • a simple docker slave node
  • a container that sets up Jenkins with:
    • jobs
      • a simple echo command with no triggers
      • a docker echo command triggered from a github push
    • credentials
    • plugins

The code is here. I welcome contributions, improvements, suggestions and corrections.

To run it yourself, ensure you have docker-compose installed:

git clone
cd jenkins-phoenix
git checkout tags/v1.0


jenkins_stateless (4)

HN Discussion here.

See here for Part II, where dynamic Docker slaves are added.

5 thoughts on “CI as Code Part I: Stateless Jenkins Deployments Using Docker

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.