I have a Gitlab CI as below. My purpose: When build stage fail, notify stage will be trigger and send email to recipients
build website:
stage: build
script: ...
send email:
stage: notify
when: on_failure
script: #send email to recipients
But in my content email, I want to use some predefined variables to refer to failure job. example: "Job $CI_JOB_NAME in stage $CI_JOB_STAGE pipelines failure". How can I refer variables to stage build from stage notify. Please help me, bro. Thanks.
In GitLab jobs are independent. If you want to share some context between jobs - you can use artifacts
build website:
stage: build
script:
- # build website
- # save whatever you want in log.txt
artifacts:
paths:
- ./log.txt
send email:
stage: notify
when: on_failure
script:
- export CI_JOB_NAME = $(cat log.txt)
- #send email to recipients