Skip to content
Latchkey

GitLab CI "Cleaning up project directory ... 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 routine teardown - the actual cause is the command output just before it.

What this error means

The job ends with "Cleaning up project directory and file based variables" then "ERROR: Job failed: exit code 1". This is generic - it only tells you a command failed, not which one without reading the log above.

Job log
$ 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 - this is the intended behavior.

Earlier command failure under set -e

GitLab runs each script line and stops on the first non-zero. 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 - fix it locally and reproduce.
  3. Re-run; the job passes once that command exits 0.

Surface which command failed

Make the script verbose so the failing step is obvious 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 named so failures are easy to localize.
  • 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 →