LoginSignup
8
7

More than 5 years have passed since last update.

Travis CIのbuild結果をSlackに通知する

Last updated at Posted at 2016-08-11

前準備

  • Travis CIで対象リポジトリを自動ビルドする
  • Slackに通知先となるchannelを作る

Travis CI設定

SlackのTravis CI integrationのSetup Instructionsに従って進める。
一番簡単にやると

  1. Integration SettingsPost to Channelに通知先channelを記載する
  2. .travis.ymlに以下を記載する
notifications:
  slack: <team name>:<token>

tokenはIntegration SettingsToken欄に記載されている。
ただ、このままだとpublicなリポジトリの場合はtokenが誰にでも見えてしまう。

Your integration token is semi-secret, but we recommend encrypting your credentials using the Travis command line client.

ということらしいので、以下の手順に従ってtokenを暗号化する。

Encryption keys - Travis CI
https://docs.travis-ci.com/user/encryption-keys/

travisのパッケージをインストール(ビルドに ruby-dev/ruby-devel が必要)

$ sudo gem install travis

token暗号化付きコマンドを実行する:

travis encrypt "<Slack team name>:<Slack API token>" --add notifications.slack
Building native extensions.  This could take a while...
ERROR:  Error installing travis:
        ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

ヘッダが無いと怒られたのでインストール。

$ sudo apt install ruby-dev

再実行し成功すると.travis.ymlに以下のSlack通知項目が追記される:

notifications:
  slack:
    secure: 
        XXX/XXX...

リポジトリの情報を見ているようなので、各リポジトリで個別に実行する必要あり

最後に対象リポジトリに.travis.ymlをコミットする。

通知結果

正しく通知設定がされている状態でビルドが成功すると↓のようにSlackチャンネルに通知してくれる:

slack_travisci_ss.PNG

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7