Skip to content
Latchkey

Bitbucket "Script exited with code 1" / Non-Zero Exit

A command in your script returned a non-zero exit code, so Bitbucket marked the step failed. This is your build or test failing - the exit code is the messenger, not the cause.

What this error means

A step ends with "The command ... exited with code 1" (or another non-zero code). The real error is in the command output just above that line - a failing test, a missing file, a linter rejection.

Bitbucket log
+ npm test
Tests: 1 failed, 42 passed
The command "npm test" exited with code 1.

Common causes

A command genuinely failed

A test failure, lint error, compile error, or failed assertion makes the underlying tool exit non-zero, which fails the step.

A missing file, dependency, or env var

A command fails because something it needs is absent - an uninstalled dependency, an unset variable, or a path that does not exist in the container.

How to fix it

Read the output above the exit line

  1. Scroll up from the "exited with code N" line to the command’s own error.
  2. Reproduce that exact command locally with the same inputs.
  3. Fix the failing command (test, lint, build) - the exit code clears once it passes.

Make failures explicit and debuggable

Echo context and avoid masking failures so the real cause is visible in the log.

bitbucket-pipelines.yml
script:
  - set -e
  - node --version && npm ci
  - npm test

How to prevent it

  • Run the same commands locally before pushing.
  • Keep set -e semantics so the step fails on the first real error.
  • Pin dependencies so CI runs the versions you tested.

Related guides

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