Drone

Slack plugin showing incorrect result

Hi all,

I’m using the Slack plugin to send messages after a pipeline succeeds/fails. I’m noticing that sometimes, incorrect statuses are shown (i.e., if a pipeline succeeds, Slack shows a “failed” notification).

Here’s a stripped down .drone.yml – I’ve omitted all of the various steps except the Slack notification at the end of each:

---
kind: pipeline
name: Linting

steps:
  # Various Steps
  - name: Send Notification
    image: plugins/slack
    settings:
      webhook:
        from_secret: slack_webhook
      channel:
        from_secret: slack_channel_name
      template: >
        {{#success build.status}}
          `{{repo.name}}/{{build.branch}}`: Linting #{{build.number}} successful
        {{else}}
          `{{repo.name}}/{{build.branch}}`: Linting #{{build.number}} failed
        {{/success}}
    when:
      status: [success, failure]

---
kind: pipeline
name: Home Assistant

steps:
  # Various Steps
  - name: Send Notification
    image: plugins/slack
    settings:
      webhook:
        from_secret: slack_webhook
      channel:
        from_secret: slack_channel_name
      template: >
        {{#success build.status}}
          `{{repo.name}}/{{build.branch}}`: Home Assistant #{{build.number}} successful
        {{else}}
          `{{repo.name}}/{{build.branch}}`: Home Assistant #{{build.number}} failed
        {{/success}}
    when:
      status: [success, failure]

---
kind: pipeline
name: ESPHome

steps:
  # Various Steps
  - name: Send Notification
    image: plugins/slack
    settings:
      webhook:
        from_secret: slack_webhook
      channel:
        from_secret: slack_channel_name
      template: >
        {{#success build.status}}
          `{{repo.name}}/{{build.branch}}`: ESPHome #{{build.number}} successful
        {{else}}
          `{{repo.name}}/{{build.branch}}`: ESPHome #{{build.number}} failed
        {{/success}}
    when:
      status: [success, failure]

---
kind: pipeline
name: NGINX

steps:
  # Various Steps
  - name: Send Notification
    image: plugins/slack
    settings:
      webhook:
        from_secret: slack_webhook
      channel:
        from_secret: slack_channel_name
      template: >
        {{#success build.status}}
          `{{repo.name}}/{{build.branch}}`: NGINX #{{build.number}} successful
        {{else}}
          `{{repo.name}}/{{build.branch}}`: NGINX #{{build.number}} failed
        {{/success}}
    when:
      status: [success, failure]

My latest run had one pipeline fail and the other three succeed:

The Slack notifications, however, don’t reflect this. Since I’m a new user and can only put one image per post, I’ll follow up with a screenshot of Slack.

if a pipeline succeeds, Slack shows a “failed” notification

The screenshot shows that the Home Assistant step failed in the Linting pipeline, in which case I would expect the Slack notification for the Linting pipeline to have a failed status.

Any pipeline that is started after Linting is complete will reflect the fact that the overall build has failed because the Linting pipeline has failed. The Slack plugin uses the overall build status when posting the message, not the individual pipeline status. This is not a requirement, but is a deliberate design decision made by the plugin authors. One could create a plugin that uses the individual pipeline status instead.

I hope this helps clarify. I am not sure there is not enough detail for me to conclude there is an issue with Drone or with the plugin. I do apologize if I am misunderstanding, however, if that is the case perhaps you could provide a more detailed report with steps to reproduce?

Thoughts?

per my previous comment this could be the expected behavior:

Any pipeline that is started after Linting is complete will reflect the fact that the overall build has failed because the Linting pipeline has failed. The Slack plugin uses the overall build status when posting the message, not the individual pipeline status. This is not a requirement, but is a deliberate design decision made by the plugin authors. One could create a plugin that uses the individual pipeline status instead.

While I appreciate that you simplified the yaml that you posted to this thread, it also has the potential to leave out important details that are required to troubleshoot, and has me asking questions and wondering what I could be missing.

The best way to get further assistance with this matter is to provide a simple, stripped down, yaml file that I can use (with the least amount of effort) to reproduce the problem.

@bradrydzewski Apologies for the disjointed and incomplete communications – my being a new user limited me to one post until my account was authorized.

This makes total sense – if the plugin was defined this way, I shouldn’t expect different results.

It’s going to be hard to provide a simple, stripped-down YAML that also includes all crucial details. :wink: All that said, let’s make sure there’s an actual problem and not just a misunderstanding from me: does my Slack message lead you to believe that the plugin isn’t acting as it should?

no worries!

there is not enough details here for me to reach that conclusion. I would need to see a more complete yaml file that is confirmed to reproduce the behavior you have described above.

Got it. If you’re willing, below is my full, production YAML (note that it now has a separate pipeline for Slack notifications, per your recommendation thus far).

  • Linting: this pipeline just runs a bunch of linters against various sections of my repo
  • Home Assistant: runs configuration checks on various versions of Home Assistant
  • ESPHome: runs configuration checks on various versions of ESPHome
  • NGINX: runs configuration checks against my NGINX config
  • Build Notification: Sends the final build notification to Slack
---
kind: pipeline
name: Linting

trigger:
  branch:
    - master
    - feature/*

steps:
  - name: AppDaemon
    image: python:3
    commands:
      - pip3 install --upgrade pip black flake8 mypy pylint yamllint
      - black --check --fast ./appdaemon/settings/apps/
      - flake8 ./appdaemon/settings/apps/
      - mypy --ignore-missing-imports ./appdaemon/settings/apps/
      - pylint --rcfile ./appdaemon/settings/pylintrc appdaemon/settings/apps/
      - yamllint ./appdaemon/settings/
  - name: ESPHome
    image: python:3
    commands:
      - pip3 install --upgrade pip yamllint
      - yamllint ./esphome/
  - name: Home Assistant
    image: python:3
    commands:
      - pip3 install --upgrade pip yamllint
      - yamllint ./home-assistant/settings/
  - name: Shell Scripts
    image: koalaman/shellcheck-alpine:stable
    pull: always
    commands:
      - shellcheck --version
      - shellcheck ./bin/*

---
kind: pipeline
name: Home Assistant

trigger:
  branch:
    - master
    - feature/*

steps:
  - name: dev
    image: homeassistant/home-assistant:dev
    pull: always
    failure: ignore
    commands:
      - cd /usr/src/app
      - "python -m homeassistant -c /drone/src/home-assistant/settings \
         --script check_config"
  - name: latest
    image: homeassistant/home-assistant:latest
    pull: always
    commands:
      - cd /usr/src/app
      - "python -m homeassistant -c /drone/src/home-assistant/settings \
         --script check_config"
  - name: rc
    image: homeassistant/home-assistant:rc
    pull: always
    commands:
      - cd /usr/src/app
      - "python -m homeassistant -c /drone/src/home-assistant/settings \
         --script check_config"

---
kind: pipeline
name: ESPHome

trigger:
  branch:
    - master
    - feature/*

steps:
  - name: beta
    image: esphome/esphome:beta
    pull: always
    failure: ignore
    commands:
      - "for file in $(find /drone/src/esphome -type f -name \"*.yaml\" -not \
         -name \"secrets.yaml\"); do esphome \"$file\" config; done"
  - name: latest
    image: esphome/esphome:latest
    pull: always
    commands:
      - "for file in $(find /drone/src/esphome -type f -name \"*.yaml\" -not \
         -name \"secrets.yaml\"); do esphome \"$file\" config; done"

---
kind: pipeline
name: NGINX

trigger:
  branch:
    - master
    - feature/*

steps:
  - name: Gixy
    image: yandex/gixy:latest
    pull: always
    commands:
      - ln -s /drone/src/nginx/settings/nginx /etc/nginx
      - gixy /etc/nginx/nginx.conf

---
kind: pipeline
name: Build Notification

trigger:
  branch:
    - master
    - feature/*

steps:
  - name: Send Notification
    image: plugins/slack
    settings:
      webhook:
        from_secret: slack_webhook
      channel:
        from_secret: slack_channel_name
      template: >
        {{#success build.status}}
          `{{repo.name}}/{{build.branch}}`: Build #{{build.number}} successful
        {{else}}
          `{{repo.name}}/{{build.branch}}`: Build #{{build.number}} failed
        {{/success}}
    when:
      status: [success, failure]

I do think there’s something going on here. The same pipeline series just produced this result:

04%20PM

…and yet I got a “success” message via Slack – since I’m still a new user, I’ll post that separately.

58%20PM

I noticed in your yaml that you have not added depends_on to ensure you notification pipeline is executed after all other pipelines complete. As a result, the notification pipeline is scheduled to execute immediately, at the same time as all your other pipelines. The slack message therefore reflects the overall build status (passing) at the time the notification pipeline was started.

see https://docs.drone.io/user-guide/pipeline/multi-machine/#dependencies

Didn’t know that existed – great! I’ll give it a shot.

One thing from the docs that I’m curious about (bolded reference mine):

In the below example, the first two pipelines execute in parallel. On successful completion a third pipeline is executed that sends a Slack notification indicating the workflow is complete.

Does this mean the final pipeline only runs if the first two are successful? Or does it mean that regardless of final status, the final pipeline merely waits for those first two to be done before executing?

if you add the following trigger to the pipeline it will always execute, even when an upstream dependency fails.

depends_on:
- backend
- frontend

trigger:
  status:
  - success
  - failure
1 Like

Got it. Thanks for your help!