2

We had slack notification working in drone.io 0.4 just fine, but since we updated to 0.5 I can't get it working despite trying out the documentation.

Before, it was like this

build:

  build and deploy stuff...

notify:
  slack:
    webhook_url: $$SLACK_WEBHOOK_URL
    channel: continuous_integratio
    username: drone

You can see here that I used the $$ to reference the special drone config file of old.

Now my latest attempt looks like this

pipeline:

  build and deploy stuff...

  slack:
    image: plugins/slack
    webhook: https://hooks.slack.com/services/...
    channel: continuous_integratio
    username: drone

According to the documentation slack is now indented within the pipeline (previously build) level.

I tried changing slack out for notify like it was before, used the SLACK_WEBHOOK secret only via the drone cli and there where other things I attempted as well.

Does anyone know what I might be doing wrong?

iehrlich
  • 3,572
  • 4
  • 34
  • 43

2 Answers2

2

This is an (almost exact) yaml I am using with slack notification enabled with the exception that I've masked the credentials

pipeline:
  build:
    image: golang
    commands:
      - go build
      - go test

  slack:
    image: plugins/slack
    webhook: https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ
    when:
      status: [ success, failure ]

There is unfortunately nothing in your example that jumps out, perhaps with the exception of the channel name having a typo (although I'm not sure if that represents your real yaml configuration or not)

If you are attempting to use secrets (via the cli) you need to make sure you sign your yaml file and commit the signature file to your repository. You can then reference your secret in the yaml similar to 0.4 but with a slightly different syntax:

pipeline:
  build:
    image: golang
    commands:
      - go build
      - go test

  slack:
    image: plugins/slack
    webhook: ${SLACK_WEBHOOK}
    when:
      status: [ success, failure ]

You can read more about secrets at http://readme.drone.io/usage/secret-guide/

You can also invoke the plugin directly from the command line to help test different input values. This can help with debugging. See https://github.com/drone-plugins/drone-slack#usage

Brad Rydzewski
  • 2,523
  • 14
  • 18
  • Thanks, though I did try the webhook substitution and I did sign my drone.yml file. Maybe I need the `when` part. I'll try that – Adam Piskorski Mar 28 '17 at 08:08
  • Also, the `continuous_integratio` is exactly how the channel is spelt (probably due to name length limitation) – Adam Piskorski Mar 28 '17 at 08:36
  • The when / status is required if you want a step to execute on failure. Drone exits the pipeline immediately on failure and will not execute any subsequent steps, unless otherwise configured to do so. – Brad Rydzewski Mar 28 '17 at 10:37
  • That might explain it, as our builds aren't passing ATM, as we have a long and complex pipeline and the last parts currently fail (not drone's fault). In 0.4 Slack was reporting the error, because it was outside the scope of the build (I presume) and now slack is inside of it (called pipeline now). At least this is how I understand it. – Adam Piskorski Mar 28 '17 at 11:57
0

The issue was that in 0.4 the notify plugin was located outside the scope of the pipeline (then build) and now since 0.5 its located inside the pipeline. This combined with the fact that when a pipeline fails it quits the scope immediately, which means the slack (then notify) step never get's reached at all anymore.

The solution to this is to just explicitly tell it to execute the step on failure with the when command:

when:
  status: [ success, failure ]

This is actually mentioned in the getting-started guide, though, but I didn't go through till the end as I was aiming to quickly get it up and running and didn't worry about what I considered to be edge cases.