Skip to content

How to Force Gitlab pipeline to fail on condition

if you have a conditional in your Gitlab pipeline stage that checks if something has succeeded or failed, then you can use this to pass or fail your pipeline stage.

Option 1 – Fail on String Found

if cat log.txt | grep "Failure Summary" ; then exit 1 ; else exit 0 ; fi
Code language: Bash (bash)

This will fail the pipeline if it find a string matching Failure Summary in a file called log.txt in the current stage.

Option 2 – Fail on Code Found

Alternatively if you have a file called response.json that contains 200 or 401 codes, then you can fail the pipeline if a 401 is found:

if cat response.json | grep 401 ; then exit 1; else exit ; fi
Code language: PHP (php)

See also  Non-interactive git clone (ssh fingerprint prompt)
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x