Skip to content
Latchkey

What Is an Exit Code? How Commands Report Success

An exit code is a small integer a program returns when it finishes, where 0 means success and any non-zero value means some kind of failure.

When a command finishes, it hands back a number that tells the shell whether it worked. Zero means success; anything else means failure. This single number is what CI uses to decide whether a step passed or failed, which makes exit codes the heartbeat of every pipeline.

What an exit code is

It is the status a process returns on exit, an integer from 0 to 255. The shell stores the most recent exit code in the special variable $?, which you can inspect right after a command runs.

Zero versus non-zero

By convention 0 means the command succeeded. Any non-zero value signals a failure, and different numbers can mean different problems, like a missing file or bad arguments.

Some common codes

  • 0: success.
  • 1: a general, catch-all error.
  • 127: command not found.
  • 130: terminated by Ctrl-C (signal interrupt).

Exit codes and control flow

The shell uses exit codes for logic. cmd && next runs next only if cmd succeeded; cmd || fallback runs fallback only if cmd failed. This is how scripts branch on success.

Exit codes in CI

A CI step passes if its final exit code is 0 and fails otherwise. With set -e, the script aborts on the first non-zero exit, so a failing command immediately fails the job instead of being ignored.

Pass and fail on managed runners

Latchkey runners report a job as failed when a step exits non-zero. Because genuine failures surface as exit codes, transient infrastructure issues can be distinguished and retried while real test or build failures stop the run.

Key takeaways

  • An exit code is the number a program returns; 0 is success, non-zero is failure.
  • The shell stores the last exit code in $? and branches on it with && and ||.
  • CI decides pass or fail from a step's exit code, especially under set -e.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →