我需要 grep 一个
的结果npm test
来 self 的 bash 条件。
所以我可以停止我的 CI/CD 环境
有一个suggestion to use grep like :
VALID="$(npm test | grep -o 'failing')"
但是当我这样做时,只是为了尝试“npm 测试”管道中的实际情况
VALID="$(npm test)"
我看到的是:
echo "$VALID"
> MyApp@0.0.1 test /Users/NE/ts/project
> jest
那么,这将如何运作? 我怎样才能真正 grep npm 测试的结果?
谢谢!
最佳答案
像“失败”这样的词是针对人类的,而不是针对计算机的。他们应该改用退出代码:
if ! npm test
then
# Tell the human about the failure, if the npm output wasn't enough
echo >&2 "Testing failed"
# Exit and tell computers about the failure (0 = success, 1+ = failure)
exit 1
fi
而且你可以更简洁地得到同样的效果:
npm test || exit
关于bash - bash 条件中 npm 测试的 grep 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54916162/