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.
$ 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 - 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
- Scroll up from "Cleaning up project directory" to the last command that ran.
- That command's output is the real error; reproduce it locally.
- Re-run once the command exits 0.
Surface which step failed
Group and label commands so the failing step stands out 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 labeled so failures localize quickly.
- Run the same commands locally before pushing.
- Use
allow_failure: trueonly for genuinely non-blocking steps.