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

Hello, i have the same problem with my pipeline, i’ve tried both ‘trigger’ and ‘when’ unfortunately when using ‘trigger’, notify step is executed everytime sending success. When using ‘when’ notify step is not triggered after any other step will fail.
image

Here is my pipeline template:

kind: pipeline
name: default

environment: &configuration
  REGISTRY_NAME: docker.registry
  PROJECT_NAME: {{ .input.projectname }}
  USERNAME:
    from_secret: registry_username
  PASSWORD:
    from_secret: registry_password

steps:
  - name: build-image
    image: docker
    environment:
      <<: *configuration
    commands:
      - docker login -u $USERNAME -p $PASSWORD $REGISTRY_NAME
      - docker build --pull -t "$REGISTRY_NAME/${DRONE_REPO_NAME}" .
      - docker push "$REGISTRY_NAME/${DRONE_REPO_NAME}"
    volumes:
      - name: docker_sock
        path: /var/run/docker.sock
  - name: deploy-image
    image: docker/compose
    environment:
      <<: *configuration
    commands:
      - docker login -u $USERNAME -p $PASSWORD $REGISTRY_NAME
      - docker-compose -p $PROJECT_NAME -f docker-compose.yaml up -d
      - throw
    volumes:
      - name: docker_sock
        path: /var/run/docker.sock
    depends_on:
      - build-image
  - name: clean-up
    image: docker
    environment:
      <<: *configuration
    commands:
      - docker rm $(docker ps --filter=status=exited --filter=status=created -q)
    volumes:
      - name: docker_sock
        path: /var/run/docker.sock
    depends_on:
      - deploy-image
  - name: notify
    image: azuruce/drone-pushover
    settings:
      user:
        from_secret: pushover_user
      token:
        from_secret: pushover_token
      device:
        from_secret: pushover_device
    when:
      status:
        include:
          - success
          - changed
          - failure
volumes:
  - name: docker_sock
    host:
      path: /var/run/docker.sock

trigger:
  branch:
  - master
  
image_pull_secrets:
  - docker-config

@Kamil_Ganczarek I see a few different problems.

First is that you are missing depends_on for your notify step. Because the notify step does not depend on any steps, it executes immediately on pipeline start, when the pipeline is in a passing state.

Second is that the third party pushover plugin you are using is attempting to read the status from CI_BUILD_STATUS environment variable. It should be using the DRONE_BUILD_STATUS environment variable instead. You would need to file an issue with the plugin author to change.

I would also point out that pipelines execute sequentially by default, unless one or more steps contain the depends_on property, in which case steps are executed as a graph. Looking at your pipeline, it seems you are defining a graph that executes all steps sequentially anyway, which means you can probably just simplify and remove depends_on entirely.

@Kamil_Ganczarek I also should mention that changed is not a valid value, and can be removed

    when:
      status:
        include:
          - success
-         - changed
          - failure