- Published on
Grep
- Authors
- Name
- Bowen Y
grep
failed with exit code 1 in CircleCI workflow
grep
will throw an error when nothing matched
$ echo "anything" | grep a
a
$ echo $?
0
$ echo "anything" | grep b
$ echo $?
1
This command behaves the same across different system environments.
grep
return 0 if nothing matched?
How to make Add || true
. If the first part of the command "fails" (meaning grep e returns a non-zero exit code) then the part after the || is executed, succeeds and returns zero as the exit code (true always returns zero).
$ echo "anything" | grep b || true
$ echo $?
0
- Can we use
| wc -l
to decide whether anything is matched instead of using|| true
?
Typically, we can. I tried on local machine as well as CircleCI SSH server CLI.
# On local machine OR CircleCI SSH server
$ echo "anything" | grep b | wc -l
0
$ echo $?
0
However, in the CircleCI automation workflow, it will raise error code 1 too.
# In CircleCI CICD workflow
$ echo "anything" | grep b | wc -l
0
Exited with code exit status 1