Last Updated: February 25, 2016
·
3.998K
· petenicholls

Encrypt your Code Climate repo token for public repositories on Travis CI

Travis and Code Climate are two great tools that go hand-in-hand.

You can actually configure Code Climate to report test coverage at the end of each Travis build. However, this requires telling Travis about a private token. If you have a publicly visible repository, you might not want to expose this token to the wider world.

Luckily, Travis supports encrypting sensitive information required by your build. Here's how to do it.

Setting up the Travis CLI

You can install the Travis command-line interface with:

gem install travis

The first step is to log in:

travis login

The Travis CLI supports multiple accounts. You can see who you are, and which accounts you have access to:

travis accounts
travis whoami

Encrypting the Code Climate repo token

Inside Code Climate, under the Test Coverage section of your repository's Settings, you can find your repo token, along with instructions to set up a command similar to this in your CI server:

CODECLIMATE_REPO_TOKEN=3f93bc9f053e7e9… bundle exec rake

First, encrypt the token:

travis encrypt 3f93bc9f053e7e9…

You should see something like this as the output:

secure: "g2pXEX+Ez3…="

Add the following to an addons section inside your .travis.yml file:

addons:
  code_climate:
    repo_token:
      secure: "g2pXEX+Ez3…="

Push and enjoy your new code coverage sync to Code Climate.