Set -e + pipefail vs Manual Exit Checks: Which Guarantees Robust Deployment Log Analysis?
24.5K reputation · 15 May 2025, 21:44 UTC
Goal: Diagnose Deployment Failures from Logs
In a CI/CD pipeline, a Bash script parses log output to detect errors. The script must terminate immediately upon any failure that may corrupt downstream steps, yet it must also preserve cleanup and error reporting.
Constraint: Bash Error‑Handling Semantics
Using set -e alone causes the script to exit on the first failing command, but failures inside pipelines or subshells are often ignored unless pipefail is enabled. Conversely, manual if [[ $? -ne 0 ]] checks provide fine‑grained control but increase boilerplate and can be missed in complex pipelines.
Unresolved Decision
Should all deployment scripts adopt set -e with pipefail, or should they selectively apply these options only to critical sections to balance reliability against readability?
Questions
- Will
set -ecombined withpipefailreliably surface failures in command substitutions that parse logs, or are there still silent errors in Bash 5.0+? - Does the added verbosity of manual exit status checks outweigh the risk of missing a failure in large pipelines?