Notify section in docker pipeline

I am trying to use the notify section within a docker pipeline and email plugin within the notify section. The below section is documented on the plugin documentation page but it has no impact when the build fails. The plugin seems to be working when it is put as an step within a pipeline.

steps:
- name: Failed step
  image: python:3.7.8-slim-stretch
  commands:
  - python hello_notify.py

- name: notify
  pull: if-not-exists
  image: drillster/drone-email
  settings:
    from: a@b.com
    host: mail.com
    username: a@b.com
    password: 
      from_secret: s
    recipients:
      - a@b.com
    subject: >
            [{{ build.status }}]
            {{ repo.owner }}/{{ repo.name }}
            ({{ build.branch }} - {{ truncate build.commit 8 }})
    body:
      https://git.io/vgvPz

notify:
  pull: if-not-exists
  image: drillster/drone-email
  host: mail.com
  username: a@b.com
  password: 
    from_secret: s
  from: a@b.com
  recipients: [ a@b.com ]
  subject: >
          [{{ build.status }}]
          {{ repo.owner }}/{{ repo.name }}
          ({{ build.branch }} - {{ truncate build.commit 8 }})
  body:
    https://git.io/vgvPz
  when:
    status: [ changed, failure ]

Something like this should work:

steps:
- name: Failed step
  image: python:3.7.8-slim-stretch
  commands:
  - python hello_notify.py

- name: notify
  pull: if-not-exists
  image: drillster/drone-email
  settings:
    from: a@b.com
    host: mail.com
    username: a@b.com
    password: 
      from_secret: s
    recipients:
      - a@b.com
    subject: >
            [{{ build.status }}]
            {{ repo.owner }}/{{ repo.name }}
            ({{ build.branch }} - {{ truncate build.commit 8 }})
    body:
      https://git.io/vgvPz
  trigger:
    status:
      - changed
      - failure

And then just omit the whole notify: part after that.

See Conditions | Drone and Triggers | Drone.

The second step is simply skipped as the first one is failed. So this approach doesn’t work.

Could you try putting the notify step before the Failed step one?

steps:
- name: notify
  pull: if-not-exists
  image: drillster/drone-email
  settings:
    from: a@b.com
    host: mail.com
    username: a@b.com
    password: 
      from_secret: s
    recipients:
      - a@b.com
    subject: >
            [{{ build.status }}]
            {{ repo.owner }}/{{ repo.name }}
            ({{ build.branch }} - {{ truncate build.commit 8 }})
    body:
      https://git.io/vgvPz
  trigger:
    status:
      - changed
      - failure

- name: Failed step
  image: python:3.7.8-slim-stretch
  commands:
  - python hello_notify.py

Just trying to put some guesses out, I’ll try to do some testing if I can get some time today.

Tried!

It is treated as normal step with a conditional trigger section. Also, at the point of the notify step the build status is still success.

Tried the below pipeline and it worked.

Instead of trigger, had to use when clause.

steps:
- name: Failed step
  image: python:3.7.8-slim-stretch
  commands:
  - python hello_notify.py

- name: notify
  pull: if-not-exists
  image: drillster/drone-email
  settings:
    from: a@b.com
    host: mail.com
    username: a@b.com
    password: 
      from_secret: s
    recipients:
      - a@b.com
    subject: >
            [{{ build.status }}]
            {{ repo.owner }}/{{ repo.name }}
            ({{ build.branch }} - {{ truncate build.commit 8 }})
    body:
      https://git.io/vgvPz
  when:
    status:
      include:
        - success
        - changed
        - failure
1 Like