Understand Vibgrate Exit Codes for Scripting and CI
Learn how Vibgrate exit codes work so you can gate pipelines on drift with --fail-on and --drift-budget, and branch on the exit code in shell scripts and CI.
Exit codes are how a scan becomes a quality gate. Vibgrate returns a non-zero exit code when a configured gate is breached, which lets shell scripts and CI pipelines block on drift. This tutorial shows how to drive exit codes with --fail-on and --drift-budget.
Prerequisites
- Vibgrate CLI installed
- Basic shell scripting familiarity
Steps
1. Run a scan and check the exit code
With no gate configured, a scan exits 0 after printing the table and DriftScore.
vg
2. Fail on a severity
Make the scan exit non-zero when findings at or above a severity are present.
vg scan --fail-on error
3. Fail on a drift budget
Gate on the DriftScore by setting a drift budget. The scan fails when the score exceeds your budget.
vg scan --drift-budget 60
4. Branch in a shell script
Inspect the exit code with $? and branch on it.
vg scan --fail-on error
if [ $? -ne 0 ]; then echo "drift gate failed"; fi
5. Use exit codes in CI
In CI, a non-zero exit code automatically fails the job, so adding --fail-on or --drift-budget turns the scan into a merge gate without extra wiring.
Verification
With no gate, echo $? after a scan prints 0. With --fail-on error or --drift-budget, the exit code is non-zero when the gate is breached and 0 otherwise. Confirm the values match your expectations on a known-good and known-bad project.
Next Steps
- Wire the gate into a pipeline with the GitHub Actions tutorial.
- Track the score over time with
vg baseline. - Produce SARIF for code scanning alongside the gate.