Maven build failed but exit code is still 0

Viewed 298

I ran Maven build ( mvn clean install) in our Jenkins pipeline, we use the Surefire plugin to run our tests, one test failed, and we see that Maven prints BUILD FAILED and that the exit code is 0. What's the reason for this? (Exit code 0 means Success)

My code looks like that:

mvn clean install
RESULT=$?
if [ $RESULT -ne 0 ];then exit 1; fi;
1 Answers

I ended up checking the log using this condition. At first, redirecting mvn output to a file

mvn clean install | tee mvn_res

And then checking the build status using grep

if grep -v 'BUILD SUCCESS' mvn_res;then exit 1; fi;
Related