Reputation: 16128
I need to grep the result of an
npm test
from my bash conditional.
So I can stop my CI/CD environment
there is a suggestion to use grep like:
VALID="$(npm test | grep -o 'failing')"
but when I do that, just to try what actually is in the pipeline for "npm test"
VALID="$(npm test)"
What I see is:
echo "$VALID"
> [email protected] test /Users/NE/ts/project
> jest
SO, how will that work? how can I really grep the result of the npm test?
thanks!
Upvotes: 1
Views: 528
Reputation: 123450
Words like "failing" are meant for humans, not for computers. They should use the exit code instead:
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
And you can get the same effect more succinctly:
npm test || exit
Upvotes: 4