如何通过 bash 脚本检测来自 ant/maven 的构建错误? [英] how to detect a build error from ant/maven via a bash script?

查看:24
本文介绍了如何通过 bash 脚本检测来自 ant/maven 的构建错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 bash 脚本来自动化构建过程.有两个主要的构建块,一个是 ant 任务,一个是普通的 mvn clean install.当这两个构建过程中的任何一个出现构建错误时,我想做一些事情.

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 to do something when there is build error coming from either of this two build processes.

问题是,这些构建会不时包含测试失败或错误,但最终结果是成功的.而且我相信无论构建失败还是成功,这些进程返回的状态代码 ($?) 都应该是 0,我可能是错的.

The problem is, these builds will contain test failures or errors from time to time, but the end result is successful. And I believe that the status code ($?) return by these processes should be 0 no matter the build fail or succeed, I could be wrong.

那么,我的脚本检测最终结果(构建失败/成功)的最佳方法是什么,而不会在构建中期(测试错误等)期间从它们那里捕获错误信息?

So what is the best way for my script to detect the end result (build fail/succeed) without catching the false info during the mid build (test errors, etc) from them?

推荐答案

mvn clean test
if [[ "$?" -ne 0 ]] ; then
  echo 'could not perform tests'; exit $rc
fi

  • $? 是一个特殊的 shell 变量,它包含最近执行的最近命令的退出代码(无论是否成功终止).
  • -ne 代表不等于".所以这里我们要测试 mvn clean 的退出代码是否不等于 0.
    • $? is a special shell variable that contains the exit code (whether it terminated successfully, or not) of the most immediate recently executed command.
    • -ne stands for "not equal". So here we are testing if the exit code from mvn clean is not equal to zero.
    • 这篇关于如何通过 bash 脚本检测来自 ant/maven 的构建错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆