mac
mac

Reputation: 43071

How to override Slack channels in Travis-CI notification when encrypting the token?

The online documentation for Travis-CI notification on Slack says:

Overriding the channel is also possible, just add it to the configuration with a # separating them from account and token.

notifications:
  slack: '<account>:<token>#development'

However, if I want to encrypt the credentials the way it is recommended:

travis encrypt "<account>:<token>" --add notifications.slack

will work just fine. But when I try:

travis encrypt "<account>:<token>#development" --add notifications.slack

I get a new encrypted token, but the notifications come on the default channel set up at integration time. What am I doing wrong?

Note: we use enterprise versions of everything (Slack, Travis, GitHub), in case this may play a role.

Upvotes: 5

Views: 1722

Answers (3)

dyltini
dyltini

Reputation: 543

You need to run the following encryption command, for every slack channel you want to include in the notifications. Make sure you keep a copy of each secure encrypted message as the command will overwrite your travis.yml every time it is run.

travis encrypt "account:token#channel1" --add notifications.slack.rooms
travis encrypt "account:token#channel2" --add notifications.slack.rooms

Finally add the tokens for each channel in the following format:

notifications:
  slack:
    rooms:
      - secure: secure_token_for_channel1
      - secure: secure_token_for_channel2

Upvotes: 1

Emerson Farrugia
Emerson Farrugia

Reputation: 11363

The command isn't correct, it's missing the .rooms property at the end. It should be

travis encrypt "account:token#channel" --add notifications.slack.rooms

Upvotes: 6

michabbb
michabbb

Reputation: 931

the encrypt command is correct:

travis encrypt "account:token#channel" --add notifications.slack

but the result inside the .travis.yml will be (wrong, and that's the problem):

notifications:
    slack: 
       secure: xxxxxxxxxxxxxxxxxxxxxx

you have to edit the .travis.yml manually after the encrypt command and add rooms, so correct is:

notifications:
  slack:
    rooms:
      secure: xxxxxxxxxxxxxx

Upvotes: 2

Related Questions