Executing Maven task from shell script and getting

2020-08-09 10:21发布

I'm executing a Maven deploy task from a bash script however even if the Maven task fails the script will continue and complete without errors.

I have tried the -e flag but that causes the deploy to fail. I also tried the following (pseudo code)

result_code= mvn deploy
if [$result_code -gt 0];then
exit 1

Any suggestions how i can identify if the deploy was successful?

标签: bash shell maven
3条回答
霸刀☆藐视天下
2楼-- · 2020-08-09 10:57

result_code=mvn deploy is not the way to get return status

you can try e.g. :

#!/bin/bash
mvn deploy
STATUS=$?
if [ $STATUS -eq 0 ]; then
echo "Deployment Successful"
else
echo "Deployment Failed"
fi
查看更多
虎瘦雄心在
3楼-- · 2020-08-09 11:00

In addition if anyone using Windows 10, here is the example which I use:

mvn deploy
if not %ERROR_CODE%==0 goto error

echo SUCCESS
goto end

:error
echo FAILED

:end
查看更多
甜甜的少女心
4楼-- · 2020-08-09 11:10

Just one other possible reason a person's mvn task may return 0 despite failing: be careful about piping the output of maven to other programs. For example, I'm using grcat (which grc is build on top of), which will always return exit code 0;

\mvn compile | grcat ~/conf.mvn

I'm not sure how to retain my nice color coding of the output. There is color_maven.sh out there but that has other issues.

查看更多
登录 后发表回答