Travis integration for Slack

2 min. read

I recently wanted to post notifications from Travis builds in a Slack channel. There is a Travis app in Slack which does exactly that.

Once you install it, it will generate a key that you can use to connect Slack with Travis. You can add this to your Travis file, as explained in their blog and in their documentation page.

They also recommend to encrypt this key. The easiest way is to install their gem to do this:


$ gem install travis
$ rbenv rehash
$ travis encrypt nameofyourkey:7q5uXtQcekdHMFRH9EGPeK6K
Shell completion not installed. Would you like to install it now? |y| n
Detected repository as `name/repository-name`, is this correct? |yes| y
Please add the following to your .travis.yml file:

  secure: "LOADS AND LOADS OF GIBBERISH"

Pro Tip: You can add it automatically by running with --add.

The pro tip was like when you read beware stickers like "don't turn me upside down" in the upside down side. TOO LATE.

The nameofyourkey is all lowercase and with no spaces.

Also, if you do as the pro tip says:


$ travis encrypt SLACK_API_KEY="nameofyourkey:7q5uXtQcekdHMFRH9EGPeK6K" --add

Then you need to pass the variable name SLACK_API_KEY, but this produces no output and adds this to your travis file:


env:
  global:
    secure: THE SAME GIBBERISH BUT WITHOUT QUOTES

What you really want to do is to use the first command and add:


notifications:
  slack:
    secure: "blah"

to your travis file. I don't know if there is a command to add this automatically, but the Pro Tip has failed me again, he he.

Comments