how to detect a build error from ant/maven via a bash script?

后端 未结 6 1194
南笙
南笙 2020-12-29 01:38

I am writing a bash script to automate the build process. There are two major build blocks, one is an ant task and one is a plain old mvn clean install. I want

6条回答
  •  执笔经年
    2020-12-29 02:09

    Correct solution for unix/linux:

    mvn clean install
    rc=$?
    if [ $rc -ne 0 ] ; then
      echo Could not perform mvn clean install, exit code [$rc]; exit $rc
    fi
    

    The "if" statement itself is a command and if it is successful, it will reset the $? variable to 0. Same goes for echo. So, you have to use an intermediary local var, for example $rc to store the return code from "mvn clean install", then it can be passed to the "exit" command as well.

提交回复
热议问题