Harith
Harith

Reputation: 571

Exit build in Jenkins when script fails

I am running Jenkins as a CI/CD pipeline for a project. To make things easier for my self, I have created a bash script to run the tests and send coverage report, here is my bash script:

#!/bin/bash

echo $GIT_COMMIT # only needed for debugging
GIT_COMMIT=$(git log | grep -m1 -oE '[^ ]+$')
echo $GIT_COMMIT # only needed for debugging

./cc-test-reporter before-build
yarn test --coverage
./cc-test-reporter after-build -t simplecov --exit-code $? || echo  “Skipping Code Climate coverage upload”

And this is how I am running it in Jenkins:

sh "jenkins/scripts/load_env_variables.sh test"

Jenkins runs the script, however when the script fails, Jenkins does not exit, rather it continues:

Jenkins build does not exit

Any help with this please?

Upvotes: 0

Views: 539

Answers (1)

Denys
Denys

Reputation: 38

Use "set -e" in script.

 -e  Exit immediately if a command exits with a non-zero status.

Upvotes: 2

Related Questions