LoginSignup
5
0

More than 5 years have passed since last update.

Drone.ioのSlack通知でauthorにmentionを飛ばす

Posted at

目的:Droneが自動テストしてくれていることを極力忘れつつも、バグを仕込んだときには肩を叩いてほしい

:thinking: DroneのWebUIをいちいち見ているのではCLIでテストするのとそう変わりない
:bulb: Slack通知プラグインを使おう
:innocent: 結局は通知先のチャンネルを確認しないと意味がない

ということで、失敗時にSlack上でmentionしてもらえるように設定します。メッセージ中の author 表示部に @ が付くイメージです。

公式ドキュメント に custom message template についての説明があるので、これを参考に以下のように template: を設定してみました。

pipeline:
  test:
    # ...
  slack:
    image: plugins/slack
    channel: drone
    secrets: [ slack_webhook ]
    when:
      status: [ success, failure ]
    template: |
      *{{build.status}}* <{{build.link}}|{{repo.owner}}/{{repo.name}}#{{build.number}}> ({{build.branch}} {{truncate build.commit 8}}) by {{#success build.status}}{{build.author}}{{else}}<@{{build.author}}>{{/success}}

<@{{build.author}}> という箇所でmentionを飛ばしていますが、この設定では commit author がSlack上での自分のアカウント名になるようにする必要があります。それができない場合は、特定のアカウント名をハードコーディングするか <!everyone> としてチャンネル全体に通知してしまいましょう。

drone-slack.png

とても快適になりました :sparkles:

5
0
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
5
0