Overview
envcheck uses standard Unix exit codes to indicate the validation results. These exit codes are essential for integrating envcheck into CI/CD pipelines, scripts, and automated workflows.
Exit Code Reference
0 - Success
Meaning: All validations passed or only warnings were found.
When it occurs:
- All checks passed successfully
- Some non-critical warnings were found, but no errors
Example scenarios:
CI/CD behavior:
- Pipeline should continue
- Deployment can proceed
- No action required
1 - Validation Failure
Meaning: One or more validation checks failed with errors.
When it occurs:
- Required tools are missing or have incorrect versions
- Required environment variables are not set
- Required ports are unavailable
- Required files do not exist
- Network endpoints are unreachable or return unexpected status codes
Example scenarios:
CI/CD behavior:
- Pipeline should fail
- Deployment should be blocked
- Errors must be fixed before proceeding
Implementation Details
The exit code logic is implemented in src/reporter.rs:92-98:
The has_errors() method checks if any validation result has an Error status:
Validation Status Levels
envcheck uses three validation status levels that affect the exit code:
Success
- Validation check passed
- Does not affect exit code
- Displayed with ✓ symbol
Warning
- Non-critical issue detected
- Does not cause exit code 1
- Displayed with ⚠ symbol
- Includes optional suggestions for improvement
Error
- Critical validation failure
- Causes exit code 1
- Displayed with ✗ symbol
- Includes optional suggestions for remediation
Using Exit Codes in Scripts
Bash Script
CI/CD Pipeline Examples
GitHub Actions
GitLab CI
CircleCI
JSON Output and Exit Codes
When using --json flag, the exit code behavior remains the same:
The passed field in JSON output indicates whether the exit code will be 0 (true) or 1 (false).
Best Practices
Use exit codes in automation:
- Always check exit codes in scripts and pipelines
- Fail fast when exit code is 1
- Log results for debugging failed validations
Warning status does not fail:
Remember that warnings do not cause a non-zero exit code. If you need warnings to fail your pipeline, you’ll need to parse the JSON output and check the warning count.