Continuous Deployment with Jenkins, Hipchat and Hubot
Here at Floodlight we are always trying to improve our development process and make things easier on ourselves. Jumping to a fully-automated testing and deploy system saved us some manual steps, improved our testing consistency, and most importantly was a huge win for our day-to-day morale.
We use an approach very similar to the one used at Github, explained in detail in this really good post by Scott Chacon. The most important piece of the flow is that master is always considered deployable—if you merged it to master, consider it live.
We have been using Jenkins from day one for our CI server, and it’s saved our bacon a number of times as we move fast and break things. Here’s how we setup Jenkins to deploy when the tests pass.
The Basic Overview
A branch is merged to master.
Jenkins is listening for changes on master and runs the test suite.
If tests passes, Jenkins automatically deploys master to production.
We live in HipChat during the day, so we made a Hubot script to enable/disable Jenkins’ continuous deployment. Hubot updates the room’s topic with the current state of CD.
Some assumptions:
You already have Jenkins up and running for your project and listening to master.
You use HipChat.
You have Hubot running.
Prerequisites:
This solution uses some Jenkins plugins, you should install them before proceeding.
Run Condition Plugin
conditional-buildstep
Parameterized Trigger Plugin
Jenkins Post-Build Script Plug-in
EnvInject Plugin
Steps:
Disclaimer: This solution is a bit duct taped together. It’s not the most elegant, but it has been stable and working nice for us.
The first step is to create a job to build the continuous deployment. This job will handle deploying your app to production. It could be as simple as an "git push heroku master" or a call to capistrano. The following is basic example of this:
Now, in our original repo (the one that just does CI), we want to build this new job when the tests are green. We could have used the parametrized build from Jenkins, but we wanted to have a way to control if the continuous deploy is enabled or disabled. So we created a conditional step that works like this:
Where the continuous deployment status script is the following:
We have a Hubot installation running in our architecture, so we can turn on and off the status of the continuous deployment easily. The Hubot script looks like the following:
Your Jenkins Dashboard should look something like the following, with both jobs setup:
Now every time you merge a branch to master, if all tests pass, the changes will be deployed to production immediately.
Have questions? Tweet us at @floodlightapp.












