Capistrano recipe for checking Travis CI build status

Using Continuous Integration is a must for any mature development process, but in the hurry of delivering to production it’s easy to forget about checking build status before issuing “cap production deploy”. What if while running Capistrano deployment, script will automatically check CI status and prevent us from delivering a broken branch?In this article, we’ll discuss how this can be easily done via Capistrano recipe. It supports only Travis CI, but can be customised to use with different CI systems.


Travis CI provides a gem for their API. This snippet allows us to fetch branch build status:To access private repository, we need access_token and Pro-account on Travis CI. I hardly imagine somebody deploying from public repository, but anyway, here is how it can be done:Now we should wrap this snippet into Capistrano recipe and prepare all stuff, like obtaining access to Travis and getting access_token.

Step by step tutorial

0. Prerequisites

You or somebody from your GitHub organization bought Pro-account for Travis CI.

1. Create account in Travis CI

Just login via with your Github account and grant Travis CI access to your repositories (in case you haven’t done it before).

2. Obtaining access_token

To get access to Pro account API, you need to obtain Travis access_token:This command asks your GitHub credentials and outputs access_token:travis token generation

3. Add ‘travis’ gem dependency

Put it into deployment Gemfile:

4. Capistrano settings

Put these variables into configuration part of your Capistrano recipes:Notice, we need “branch”-variable and this part can differ for your capistrano configuration.

5. Capistrano recipe

Copy this recipe into your recipes directory:

6. Enable ci:verify task

Drop this line in front of your deployment steps:

7. Run deploy

And what we have on the failed build status: travis ci verify in actionThat’s it. Now on every deploy ci:verify will check build status and notify you in case of broken build.