How to receive notifications on a failure after allow_failure: true?

We have a pipeline which includes several jobs. Some of the jobs are allowed to fail while the pipeline as a whole should succeed. We use allow_failure: true on those jobs. The problem is that we still need to be notified if any of the jobs marked ‘allow_failure: true’ do end up failing. How can we accomplish this?

To help clarify, here is a sample .gitlab-ci.yml file. In this sample, lint-js fails and notify-on-fail never runs. We want notify-on-fail to run when lint-js fails.

stages:
  - lint-css
  - lint-js
  - notify-on-fail
  - unit-test

image: node:6.11.2

lint css:
  stage: lint-css
  before_script:
    - npm install
  cache:
    untracked: true
  only:
    - master
  script:
    - ./node_modules/gulp/bin/gulp.js lint-css

lint js:
  stage: lint-js
  cache:
    untracked: true
    policy: pull
  only:
    - master
  script:
    - ./node_modules/gulp/bin/gulp.js lint-js
  allow_failure: true

notify on failure:
  stage: notify-on-fail
  when: on_failure
  script:
    - "curl -X POST -H 'Content-Type: application/json' --data '{\"text\":\"JS lint failed\"}' https://chat.domain.com/hooks/{$TOKEN}"
 
run unit test:
  stage: unit-test
  cache:
    untracked: true
    policy: pull
  only:
    - master
  script:
    - ./node_modules/gulp/bin/gulp.js test

If it is not possible to do this within the .gitlab-ci-yml file, is there another way to detect a failed job that is marked ‘allow_failure: true’?

We saw that emails used to go out when a job was marked with ‘allow_failure: true’, but the behaviour was changed. https://gitlab.com/stanhu/gitlab-ce/commit/69209612e1793fcebcdb784074056d7a02b0f6f7

Edit: added ci tag

1 Like

Same issue.

Same issue here. Did you ever find a solution?

No solution yet.

hi,
any solution for this ?

We have not looked in awhile.