How to read pipeline output from gitlab-ci after-script?

I created an after-script to purge CDN files to prevent collision after each build, but if the build itself failed, it would result at the after-script running anyways and it too would fail (since those CDN files were never created).

 [Pipeline] }
 [Pipeline] // stage
 [Pipeline] }
 [Pipeline] // node
 [Pipeline] End of Pipeline
 ERROR: script returned exit code 1
 Finished: FAILURE

How can I read the pipeline output from the after-script so I could get the last line Finished: FAILURE and thus know the build went wrong.

Hi @aeroxy

I think you want the CI_JOB_STATUS environment variable. The documentation for it says:

The status of the job as each runner stage is executed. Use with after_script . Can be success , failed , or canceled .

1 Like