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

1.7k views Asked by At

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.

3

There are 3 answers

0
Emerson Farrugia On BEST ANSWER

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
0
dyltini On

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
0
michabbb On

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