Skip to content
Latchkey

GitLab CI "Job failed: exit code 1"

A command in your script exited non-zero, so GitLab marked the job failed. The "Cleaning up project directory" line is teardown - the actual cause is the command output above it.

What this error means

The job ends with "Cleaning up project directory and file based variables" then "ERROR: Job failed: exit code 1". The message is generic: it confirms a command failed but not which one.

gitlab-ci
$ npm test
Tests: 1 failed, 42 passed
npm ERR! Test failed.  See above for more details.
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1

Common causes

A real command failure

A test, build, lint, or deploy command returned non-zero. The exit code propagates and fails the job - the intended behavior.

Earlier failure under set -e

GitLab stops the script at the first non-zero command, so the failing line may be several commands before the final cleanup output.

How to fix it

Read the log above the cleanup line

  1. Scroll up from "Cleaning up project directory" to the last command that ran.
  2. That command's output is the real error; reproduce it locally.
  3. Re-run once the command exits 0.

Surface which step failed

Group and label commands so the failing step stands out in the log.

.gitlab-ci.yml
script:
  - set -e
  - echo "::group::test" && npm test && echo "::endgroup::"
  - echo "build step" && npm run build

How to prevent it

  • Keep scripts small and labeled so failures localize quickly.
  • Run the same commands locally before pushing.
  • Use allow_failure: true only for genuinely non-blocking steps.

Related guides

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