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.
$ 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 1Common 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
- Scroll up from "Cleaning up project directory" to the last command that ran.
- That command’s output is the real error - fix it locally and reproduce.
- 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.
script:
- set -e
- echo "::group::test" && npm test && echo "::endgroup::"
- echo "build step" && npm run buildHow to prevent it
- Keep scripts small and named so failures are easy to localize.
- Run the same commands locally before pushing.
- Use
allow_failure: trueonly for genuinely non-blocking steps.