I have written few jobs in .gitlab-ci.yml and my question is similar to this one SO Question. However, the answers provided and accepted doesn't work for my scenario.
The job has an after_script section which executes when the main task completes or fails.
Problem: I send an email alert based on whether the main task succeeded or failed, but I can't find any Gitlab CI variable that indicates the result of the job to clarify in the alert email.
How can I tell, inside the after_script section, whether the main task has succeeded or failed?"
If I use when: on_failure, then my question is when can I define my when: on_success job, since these jobs will depend on the job right before the one - so I can only execute one of these. I've been trying to find variables in Gitlab Variables for this, but couldn't find.
Also, in my after script - I can write if condition, but I am checking if someone can provide better alternate soltion