在 Spinnaker 中配置 Slack 警报

Configure Slack alerts in Spinnaker

当 spinnaker 管道失败时,我们可以看到以下内容:

Spinnaker Alerts Bot APP [3:24 PM]
Stage failed for APP_NAME
Stage STAGE_NAME for APP_NAME's PIPELINE_NAME has failed

OTHER STUFF FROM NOTIFICATION CONFIG PANEL OF STAGE

Spinnaker   Today at 3:24 PM

配置 "OTHER STUFF" 很容易,但是前 3 行呢?在 Spinnaker UI 中没有找到执行此操作的地方,也许是在服务器上的配置文件中?

它没有记录,但如果您编辑通知的 JSON,您可以添加一个 customMessage 字段,这将覆盖默认的三行消息。

例如,将舞台 JSON 中的 notifications 字段更改为:

"notifications": [
    {
      "address": "my-slack-channel",
      "customMessage": "this will replace all three of the standard message lines, and can contain HTML",
      "level": "stage",
      "type": "slack",
      "when": [
        "stage.failed"
      ]
    }
  ]

你会看到:

Spinnaker Alerts Bot APP [3:24 PM]
this will replace all three of the standard message lines, and can contain HTML

Spinnaker   Today at 3:24 PM

这是最新版本 spinnaker 1.16.5 的更新:自定义消息可针对每种通知类型(开始、失败、完成)进行编辑。似乎不能将 html 放入其中,但可以放置标记。我不知道这个 post 的内容是在哪个版本的 spinnaker 上实现的,我只知道它适用于 1.16.5。

此外,一旦您将其中一个管道配置为使用通知,您可以将通知的 JSON 复制到其他管道,以便轻松地对它们进行相同的配置(或作为起点)。

所以我有以下 JSON 用于我们的 Slack 通知,请注意使用的管道参数及其粗体标记:

  "notifications": [
    {
      "address": "spinnaker-notifications",
      "level": "pipeline",
      "message": {
        "pipeline.failed": {
          "text": "SERVICE_NAME: *${ parameters['SERVICE_NAME'] }*\nSERVICE_VERSION: *${ parameters['SERVICE_VERSION'] }*"
        },
        "pipeline.starting": {
          "text": "SERVICE_NAME: *${ parameters['SERVICE_NAME'] }*\nSERVICE_VERSION: ${ parameters['SERVICE_VERSION'] }"
        }
      },
      "type": "slack",
      "when": [
        "pipeline.failed"
      ]
    }
  ],

消息文本很容易通过“通知”对话框进行配置,只是 JSON 包含嵌入的 \n 等。