Global notify rule if build / deploy or destroy fails

I want to push an “alert” curl job to a specific system when a deploy, build or destroy fails.

Currently I added a step notify after the step before so:

  • plan
  • deploy
  • notify
  • destroy
  • notify 2

Is there a way then you can create 1 notify that works global on all three steps? Or at least on deploy and destroy?

Sorry for the N00B question :slight_smile: But thnx for the help

Hey there,

This really all depends on how specific you want your notifications to be.

I think up front, you may want to look into webhooks instead. These may be able to accomplish what you need.

If you are okay with a somewhat vague notification, you could create a single global notification that has a

when: on_failure

That will only run when a previous job failed. The notification will not have specifics about which job failed unless you did a Gitlab API call for the current pipeline.

If you keep the same structure you have in your question, you could try creating a template within your .gitlab-ci.yml that looks like

.notification_template:
   tags: runner
   script:
      - your notify script with template ENV VARS

Then call it using the extends keyword

notify_1:
  stage: notify_1
  extends: .notification_template
  variables:
    JOB_FAILED: “Job deploy failed”