Safeguard
Developer Tools•

How does a scanner make a CI pipeline fail? Exit codes explained

A gate is just a process that exits non zero. How exit codes, pipes and status checks connect, and the mistakes that turn a failing scan green.

Safeguard Security Team
3 min read

A CI step fails when its command exits with a non zero code. A security gate is a scanner that returns non zero when findings cross your threshold. Everything else, from the red cross on a pull request to a blocked merge, follows from that one number.

The chain from scanner to merge button

  1. The scanner runs and decides pass or fail using your threshold.
  2. It exits with 0 for pass or a non zero code for fail.
  3. The CI job reports success or failure based on that code.
  4. CI posts a commit status or check to the pull request. A commit status has one of four states: error, failure, pending or success.
  5. Branch protection requires that check, so the merge button follows it.

A break at any link yields a gate that looks fine and blocks nothing.

What the code means in practice

The npm audit documentation is a good example. It exits 0 when no vulnerabilities are found, and by default exits non zero if any are found. With an audit level set, the exit code depends on that level, so a run can exit 0 even with findings below the level. The fix command exits 0 when no vulnerabilities remain after the fix.

Notice that the code is decided by the threshold, not by what was printed. People often read the report and assume the build will fail. It may not.

Mistakes that turn a failing scan green

MistakeWhy it hides failure
Piping scanner output to another commandThe shell reports the last command's code
Adding "or true" after the commandForces exit 0
Setting the job to continue on errorJob reports success despite failure
Wrapping in a script without propagating the codeThe wrapper exits 0
Treating a scanner crash as a passErrors and findings use different codes

That last one deserves care. A scanner that cannot reach its database may exit with an error. Decide in advance whether an error blocks. Our post on what to do when the scanner is down covers the tradeoff.

Steps to verify your pipeline

  1. Run the scanner locally against a known vulnerable project and echo the exit code.
  2. Run the same command inside the CI job and compare.
  3. Search your pipeline files for continue on error and the pipe character near scan commands.
  4. Confirm the resulting check is marked required.

Keep the contract documented

Write a short note in the repository: which code means findings, which means tool error, and which action each triggers. When a new person edits the pipeline, they should not have to rediscover it.

Quick check

Does a scanner that prints findings always fail the build?

No. The exit code decides, and it depends on your threshold settings.

What should happen if the scanner itself errors?

Decide up front. Many teams block on error for protected branches and warn elsewhere.

Safeguard's CLI can run in a pipeline and report policy results, and its gates apply your rules to the outcome. Try the free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.