How to Force Gitlab pipeline to fail on condition

0 min read 123 words

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

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 0 ; fi
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags