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

后端 未结 6 1220
南笙
南笙 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:11

    There's a command built-in to bash which performs exactly this.

    # exit when any command fails
    set -e
    

    I put this at the top of my bash scripts, which I copied from this excellent resource.

    # keep track of the last executed command
    trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
    
    # echo an error message before exiting
    trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
    

提交回复
热议问题