Join us

Capistrano recipe for your favourite CI

Last updated August 16, 2021 2 min read

The quality of features going to production is very important; and to guarantee the highest quality we use Continuous Integration in our everyday workflow. In one of his recent posts Sergii Boiko has described how to check Travis CI build status before delivering new code to production. Afterwards, we’ve also decided to extract this recipe to capistrano-ci gem and this article will explain how to setup this gem in your deployment process.

Supported continuous integration services:

Installation

Add the following line to your application’s Gemfile:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
gem 'capistrano-ci'
gem 'capistrano-ci'
gem 'capistrano-ci'

And then execute:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ bundle
$ bundle
$ bundle

Or install it yourself as:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ gem install capistrano-ci
$ gem install capistrano-ci
$ gem install capistrano-ci

Add to your Capfile:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
require 'capistrano/ci/recipes'
require 'capistrano/ci/recipes'
require 'capistrano/ci/recipes'

Configuration

Variables list:

  • :ci_client (required) – supports travis, travis_pro, circle, or semaphore
  • :ci_repository (required) – organization or user name and repository name on github
  • :ci_access_token(required for travis_pro, circle, or semaphore) – access token specific to the service

Open Source Projects

Setup ci_client and ci_repository variables in your deployment script:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
set(:ci_client){ "travis" }
set(:ci_repository){ "organisation-or-user/repository-name" }
set(:ci_client){ "travis" } set(:ci_repository){ "organisation-or-user/repository-name" }
set(:ci_client){ "travis" }
set(:ci_repository){ "organisation-or-user/repository-name" }

Pro Account of Travis-CI:

Additional to ci_client and ci_repository setup ci_access_token:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
set(:ci_client){ "travis_pro" }
set(:ci_repository){ "organisation-or-user/repository-name" }
set(:ci_access_token){ "your-pro-access-token" }
set(:ci_client){ "travis_pro" } set(:ci_repository){ "organisation-or-user/repository-name" } set(:ci_access_token){ "your-pro-access-token" }
set(:ci_client){ "travis_pro" }
set(:ci_repository){ "organisation-or-user/repository-name" }
set(:ci_access_token){ "your-pro-access-token" }

To have more information about Travis-CI access token, you can follow this blog post.

CircleCi:

Setup ci_client, ci_repository and ci_access_token in your deployment script:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
set(:ci_client){ "circle" }
set(:ci_repository){ "organisation-or-user/repository-name" }
set(:ci_access_token){ "your-circle-access-token" }
set(:ci_client){ "circle" } set(:ci_repository){ "organisation-or-user/repository-name" } set(:ci_access_token){ "your-circle-access-token" }
set(:ci_client){ "circle" }
set(:ci_repository){ "organisation-or-user/repository-name" }
set(:ci_access_token){ "your-circle-access-token" }

Semaphore:

Setup ci_client, ci_repository and ci_access_token in your deployment script:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
set(:ci_client){ "semaphore" }
set(:ci_repository){ "organisation-or-user/repository-name" }
set(:ci_access_token){ "your-semaphore-access-token" }
set(:ci_client){ "semaphore" } set(:ci_repository){ "organisation-or-user/repository-name" } set(:ci_access_token){ "your-semaphore-access-token" }
set(:ci_client){ "semaphore" }
set(:ci_repository){ "organisation-or-user/repository-name" }
set(:ci_access_token){ "your-semaphore-access-token" }

Enable ci:verify task:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
before 'deploy' do
ci.verify
end
# or in case of using capistrano-patch:
before 'patch:create' do
ci.verify
end
before 'deploy' do ci.verify end # or in case of using capistrano-patch: before 'patch:create' do ci.verify end
before 'deploy' do
  ci.verify
end

# or in case of using capistrano-patch:
before 'patch:create' do
  ci.verify
end

Summary

That’s it, and in case your CI system isn’t supported by our gem, ask us to add it or make pull-requests by yourself!