构建失败时如何获得松弛通知?

How to get a slack notification when build fails?

当我的构建成功时,我会收到一个 slack 通知,当它失败时,我不会。查看 Drone web UI 看起来它会在构建失败后停止并且 slack plugin 永远不会 运行.

成功构建导致 notify 发生:

失败的构建没有进入通知阶段:

.drone.yml的关键部分如下:

  build:
    image: propheris/ruby:2.4.0
    secrets: [gems_password]
    commands:
      - exit 0     

  notify:
    image: plugins/slack
    webhook: https://example.com/hooks/token
    channel: dev
    username: drone
    icon_emoji: drone

我更改 exit 0exit 1 以模拟成功或失败的构建。

我查看了文档,您似乎缺少以下行:

when:
    status: [ success, failure ]

docs状态:

Example configuration for success and failure messages:

pipeline:
  slack:
    image: plugins/slack
    webhook: https://hooks.slack.com/services/...
    channel: dev
    when:
      status: [ success, failure ]

您还可以添加自定义消息:

Example configuration with a custom message template:

pipeline:
  slack:
    image: plugins/slack
    webhook: https://hooks.slack.com/services/...
    channel: dev
    template: >
      {{#success build.status}}
        build {{build.number}} succeeded. Good job.
      {{else}}
        build {{build.number}} failed. Fix me please.
      {{/success}}