Script exiting on failed nosetests

I am using a small script to merge current branch into the trunk and push it out. How can I make the script fail if nosetests fails?

#!/bin/bash
git checkout $1
nosetests
git checkout master
git merge $1
git push
git checkout $1

2 Answers

Add set -e after the shebang line to make the script exit if any of the command fails:

#!/bin/bash
set -e
git checkout $1
nosetests

From help set:

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

You could try the following.

#!/bin/bash
git checkout $1
nosetests || exit 1
git checkout master
git merge $1
git push
git checkout $1

The || will check the return code of nosetests and will execute the command exit 1 if it is non-zero.

Another variant could be.

#!/bin/bash
git checkout $1
if ! nosetests
then exit 1
fi
git checkout master
git merge $1
git push
git checkout $1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like