Consider this .gitlab-ci.yml:
variables:
var1: "bob"
var2: "bib"
job1:
script:
- "[[ ${var1} == ${var2} ]]"
job2:
script:
- echo "hello"
after_script:
- "[[ ${var1} == ${var2} ]]"
In this example, job1 fails as expected but job2 succeeds, incomprehensibly. Can I force a job to fail in the after_script section?
Note: exit 1 has the same effect as "[[ ${var1} == ${var2} ]]".
The status of a job is determined solely by its script:/before_script: sections (the two are simply concatenated together to form the job script).
after_script: is a completely different construct -- it is not part of the job script. It is mainly for taking actions after a job is completed. after_script: runs even when jobs fail beforehand, for example.
Per the docs: (emphasis added on the last bullet)
Scripts you specify in
after_scriptexecute in a new shell, separate from anybefore_scriptorscriptcommands. As a result, they:
- Have the current working directory set back to the default (according to the variables which define how the runner processes Git requests).
- Don’t have access to changes done by commands defined in the
before_scriptorscript, including:
- Command aliases and variables exported in
scriptscripts.- Changes outside of the working tree (depending on the runner executor), like software installed by a
before_scriptorscriptscript.- Have a separate timeout, which is hard-coded to 5 minutes.
- Don’t affect the job’s exit code. If the
scriptsection succeeds and theafter_scripttimes out or fails, the job exits with code0(Job Succeeded).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With