Digdagでエラー発生時にSlack通知をする


概要

Digdagでエラー発生時にSlack通知をする。
Slackのincoming-webhookアプリでWebhook URLの発行を事前にしておき、下記SLACK_INCOMING_WEBHOOK_URLの値として記載する。
※以下サンプルは#general@channel通知なので注意。

slack_test.dig
_export:
  SLACK_INCOMING_WEBHOOK_URL: https://hooks.slack.com/services/xxxxxx/xxxxxx/xxxxxxxxxxxxxxxxxxxxx

_error:
  http>: ${SLACK_INCOMING_WEBHOOK_URL}
  method: POST
  content:
    username: "Digdag workflow"
    icon_emoji: ":x:"
    channel: "#general"
    attachments:
    - title: "Workflow failed!"
      text: <!channel> Error occurred! ${task_name}
      color: danger
  content_format: json

# 存在しないシェルを実行してエラー終了する
+step1:
  sh>: sh exec_not_exist.sh

実行

> digdag run test.dig -a

結果(Slack通知)

メモ

エラー発生時に以下の様に ${error.message}, ${error.stacktrace} でエラーの内容を参照・通知可能。

      text: <!channel> Error occurred! ${error.message}, ${error.stacktrace}

ただし下記の通り、Digdag自体のエラーなので見る必要なさそう。

参考