我正在制作一个预提交脚本。它看起来是这样的:
function presubmit() {
gradle test android
gradle test ios
gradle test server
git push origin master
}如果任何测试失败,我希望函数退出,这样它就不会将bug推到git上。多么?
发布于 2017-10-06 10:44:18
我会让脚本更细粒度:
#!/bin/bash
function test() {
gradle test android
gradle test ios
gradle test server
}
function push() {
git push origin master
}
# this subshell runs similar to try/catch
(
# this flag will make to exit from current subshell on any error inside test or push
set -e
test
push
)
# you catch errors with this if
if [ $? -ne 0 ]; then
echo "We have error"
exit $?
fi我们只在测试和推送中跟踪错误。您可以在测试和推送运行的subshell之外添加更多操作。您还可以通过这种方式为错误添加不同的作用域(让我们将其视为try/catch)
https://stackoverflow.com/questions/40429865
复制相似问题