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
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
- your notify script with template ENV VARS
Then call it using the extends keyword
JOB_FAILED: “Job deploy failed”