LoginSignup
18
15

More than 5 years have passed since last update.

BitbucketとSlack、Wercker連携してみる

Posted at

こんにちは。

本記事はIwate Developers Advent Calendar 2014の8日目になります。

今回はRailsアプリケーションでBitbucketにpushして、werckerのbuild結果をslackに表示するところまでやります。
今回は既にBitbucketにレポジトリが配置してあることを前提としています。

BitbucketとWercker連携

まずはWerckerにログインしてください。その後、add applicationをサイドバーから選択します。

Screen Shot 2014-12-08 at 1.02.48.png

次にBitbucket連携してます。
wercker.png

そうすると、レポジトリを見れるようになるので好きなアプリケーションを選択してください。

wercker.png

アクセス権について、設定します。今回は一番上の「Add the deploy key to the selected repository for me」を選択肢ます。

Banners_and_Alerts_and_wercker.png

ここではwercker.ymlを生成されますが、特に何もせずに「Next Step」しましょう。

wercker.png

最後にFinishをクリックします。
wercker.png

次はWerckerとSlack連携していきましょう。

WerckerとSlack連携

SlackにログインしてサイドバーのIntegrationsをクリックします。

Integrations___offsidenow_Slack.png

そこから、Incoming WebHooksを選択します。

Integrations___offsidenow_Slack.png

次は投稿するChannelを選択します。
Team_Integration___offsidenow_Slack.png

そして、WebHookのURLをコピーしてください。これはwercker.ymlの設定で使います。

Team_Integration___offsidenow_Slack.png

wercker.ymlを設定

wercker.ymlはRailsのトップディレクトリに保存します。
wercker.ymlのafter-stepsに各種、設定を追記します。先ほどコピーしたURLをここのYOUR_WEBHOOK_URLに貼り付けくてださい。

wercker.yml
box: wercker/rvm
# Build definition
# See the Rails section on the wercker devcenter:
# http://devcenter.wercker.com/articles/languages/ruby/settingup-rails4.html
# You will want to define your database as follows:
# services:
#   - wercker/postgresql
# See more about services on our devcenter:
# http://devcenter.wercker.com/articles/services/
build:
    steps:
        # Uncomment this to force RVM to use a specific Ruby version
        # - rvm-use:
        #       version: 2.1.5

        # A step that executes `bundle install` command
        - bundle-install

        # A step that prepares the database.yml using the database in services
        # - rails-database-yml

        # A custom script step, name value is used in the UI
        # and the code value contains the command that get executed
        - script:
            name: echo ruby information
            code: |
                echo "ruby version $(ruby --version) running"
                echo "from location $(which ruby)"
                echo -p "gem list: $(gem list)"

    after-steps:
        - wantedly/pretty-slack-notify:
            team: YOUR_TEAM
            webhook_url: YOUR_WEBHOOK_URL
            channel: YOUR_CHANNEL

では、

ここでは、簡易的にmaster pushしちゃってますが、ご了承ください。

$ git add wercker.yml
$ git commit -m 'add wercker.yml'
$ git push origin master

いかがでしょうか。buildが成功したら、Slackに以下のようなものが投稿されたと思います。もしできなかった方はWerckerからbuildのリンクをクリックして原因を調べてみてください。

Screenshot_12_8_14__1_27.png

最後に

駆け足ではありましたが、BitbucketとSlack、Wercker連携してみるところまでやってみました。かなり簡単にできたと思います。

ここまで、全部無料ですので、プライベートプロジェクトではこの組み合わせを使ってみてはいかがでしょうか。

参考記事

18
15
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
18
15