Exit codes: make CI fail for the right reasons

CI only understands one thing about your API tests: the exit code of the command. Zero, the step is green. Anything else, red. Getting that right decides whether a failing build means "the API broke" or "someone rotated a token".

What counts as a failure

requestarium run and run-collection exit with 1 when any request:

  • failed: a pm.test or a check in the Tests tab failed, or, for a request with no tests, the status was 400 or more;
  • errored: it couldn't be sent at all: unreachable host, timeout, an unresolved {{variable}}, a script error.

A request with tests passes when all its tests pass, whatever the status code. So a test that expects 404 makes a 404 a pass.

Gates

Two options turn "every request passed" into something more forgiving or stricter:

Terminal
requestarium run-collection "Checkout" --env Staging --max-p95 800
requestarium run-collection "Checkout" --env Staging --min-pass-rate 98
  • --max-p95 800 also fails the run when the 95th percentile response time is over 800 ms, even if every test passed.
  • --min-pass-rate 98 fails only when fewer than 98% of requests pass. With it, a single failed request doesn't fail the run on its own.

Use the pass rate for long nightly suites where one flaky third-party sandbox shouldn't wake anyone. Don't use it for deploy gates on critical paths: there, any failure should stop the deploy. More in how to deal with flaky API tests.

"The API broke" vs "the pipeline broke"

Both exit 1. Your script can tell them apart, because only a real run writes a report:

Terminal
set +e
requestarium run-collection "Checkout" --env Staging --out report.json --junit results.xml
code=$?
set -e

if [ "$code" -ne 0 ] && [ ! -s report.json ]; then
  echo "::error::The API tests could not start. Check the token, the API URL and the collection name."
  exit 2
fi
exit "$code"

Now the CI log says "could not start" for a revoked token, and the JUnit report explains a real API failure. Exit code 2 is a convention many pipelines use for "infrastructure problem"; pick what your team prefers.

The ready-made GitHub Action does the same: 0 passed, 1 failed, 2 when the step was set up wrong (no token, no target).

Things that never change the exit code

  • Saving the run. If --save-run can't save (no permission, network blip), the CLI prints why on stderr and still exits with the run's own result.
  • Jira. With --jira-on-failure, Jira problems are printed and ignored for the exit code.
  • The update notice. It's off in CI anyway.

Keep failures informative

An exit code says that something failed. Make the log say what:

  • --junit results.xml for your CI's test view; inside GitHub Actions the CLI also writes a job summary and an error annotation per failed request.
  • --html report.html as a build artifact for people who don't read logs.
  • Test names that explain themselves. See name API tests so a failure explains itself.

Don't hide failures with || true

requestarium run-collection … || true makes every build green, which is the same as not testing. If a test is known to fail, fix it, delete it, or move it to a folder you don't run in that pipeline:

Terminal
requestarium run-collection "Checkout" --folder "Stable" --env Staging