GitLab CI "ERROR: Job failed: exit code 1": find the command that failed
Short answer
"ERROR: Job failed: exit code 1" usually means a command in the job's before_script or script exited with 1. GitLab Runner runs them in one shell with errexit on, and pipefail where the shell has it, so the first command that fails stops the job, and its exit code becomes the job's. The shell executor says exit status 1 instead, and Kubernetes says command terminated with exit code 1. The failing command is the last line starting with $ before any Running after_script section, and its output explains why. Common causes are failing tests or linters, grep finding no match, and a test with && on the last line. If every command passed and a FATAL: line such as FATAL: too large sits under an artifacts section, the runner's artifact step failed instead. Fix the command, add || true where a non-zero code is normal, or allow the code with allow_failure: exit_codes.
A job ends with this line:
ERROR: Job failed: exit code 1
The shell executor says ERROR: Job failed: exit status 1, and the Kubernetes executor ERROR: Job failed: command terminated with exit code 1. It’s usually not a GitLab error: a command in your script exited with 1, and the runner passed that code on. Here’s how to find the command and fix it, with GitLab Runner 19.5.
Find the command that failed
Scroll up from the error to the last line that starts with $ before any Running after_script section, whose commands are printed with $ too. That’s the command that failed, and its output below it usually says why:
$ npm run lint
...
✖ 3 problems (3 errors, 0 warnings)
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1
Sections such as Running after_script, Uploading artifacts for failed job and Cleaning up project directory and file based variables can sit in between. They run after the failure and aren’t the cause.
If every $ command passed, look for a FATAL: line under an Uploading artifacts or Downloading artifacts section, such as FATAL: too large. The runner’s own artifact step failed, and it ends with exit code 1 too: see GitLab CI artifacts.
If the line ends in # collapsed multi-line command, the failure is somewhere in that block. Make set -x its first line, and the shell prints each command before it runs it:
script:
- |
set -x
npm ci
npm run build
For a trace of the whole job, set the variable CI_DEBUG_TRACE: "true". It also prints every variable, secrets included, into the log, so turn it on only where just your team can read job logs, and delete those logs afterwards.
Why the first failure stops the job
On Linux, GitLab Runner runs before_script and script together in one bash or sh shell, with errexit on, and pipefail where the shell has it, as bash does. So a command that exits with anything but 0 ends the job, and the job reports that code:
| In your script | What happens |
|---|---|
| A command exits with 1 | The job stops there, with exit code 1 |
make piped into tee, and make fails |
The job stops: pipefail fails the whole pipe |
false && echo ok on a middle line |
Nothing: a failure before && doesn’t stop the shell |
test -f out.txt && ./deploy.sh on the last line |
If the test is false, the job fails with exit code 1 |
A failing if condition |
Nothing |
The last-line case surprises people. A script’s exit code is its last command’s, so a false test there fails the job even though nothing went wrong.
after_script runs afterwards in a separate shell, and by default its failures don’t change the job’s result.
Common causes
- Tests, linters and type checks exit with 1 when they find problems. The output above the error lists them.
grepfound nothing. It exits with 1 when no line matches, anddiffdoes when the files differ, so a search that comes up empty fails the job.- A missing file or folder, such as
cd distbefore anything built it, or a path that exists only on your machine. Bash exits with 1 there; theshin Alpine and Debian images exits with 2. - A failed install, such as
npm ciwith a lock file that doesn’t matchpackage.json.
Other codes point elsewhere: 126 means a file couldn’t be run, usually a script that isn’t executable, 127 means a command wasn’t found, and 137 means the process was killed, usually for running out of memory.
Fix it, or allow it
Fix what the output says, and push a commit. A retry runs the same commit, so it only helps with flaky failures, such as a network timeout.
Expect non-zero codes where they’re normal:
script:
- grep "WARN" build.log || true
- if [ -f dist/report.json ]; then ./upload-report.sh; fi
- status=0; ./check.sh || status=$?
- if [ "$status" -gt 1 ]; then exit "$status"; fi
Let the pipeline carry on when a job fails with a code you expect:
lint:
script:
- npm run lint
allow_failure:
exit_codes: 1
The job shows a warning instead of failing the pipeline, and any other exit code still fails it. More in GitLab CI allow_failure.
Catch failures before && too. With this runner feature flag in the job’s or the pipeline’s variables, the runner checks each script entry’s exit code after it runs, instead of relying on set -e alone. A false test such as [ -f out.txt ] && ./deploy.sh then fails the job on any line, so turn those into if statements first. A multi-line block counts as one entry, checked once at its end:
variables:
FF_ENABLE_BASH_EXIT_CODE_CHECK: "true"
On your phone
MergeBell shows a job’s log live, so you can scroll up from the error to the failing $ line and its output, and Retry reruns the job on the free tier. A retry helps only with flaky failures; a real one needs a new commit. More in how to retry a failed GitLab pipeline.
Frequently asked questions
What does "ERROR: Job failed: exit code 1" mean in GitLab CI?
Usually, a command in the job's before_script or script exited with code 1, and the runner stopped the job there. GitLab Runner runs those commands in one shell with errexit on, so the first command that fails ends the job, and its exit code becomes the job's. The shell executor says exit status 1 instead, and the Kubernetes executor says command terminated with exit code 1. If the script passed and a FATAL: line such as FATAL: too large sits under an artifacts section, the runner's artifact step failed instead.
How do I find which command failed in a GitLab job?
Scroll up from the error to the last line that starts with $ before any Running after_script section, whose commands are printed with $ too. That's the command that failed, and its output just below it says why. Sections such as Cleaning up project directory and file based variables run after the failure and aren't the cause. If that line ends in # collapsed multi-line command, make set -x the block's first line, and the shell prints each command as it runs.
Why does grep make my GitLab CI job fail?
grep exits with 1 when nothing matches, and the runner treats any non-zero exit code as a failure, so a search that finds nothing fails the job. Add || true where no match is fine, or test the result in an if statement. diff does the same when the files differ.
Why doesn't a failed command before && stop my GitLab job?
Bash's errexit doesn't stop the script when a command before && or || fails, or when an if condition fails, so the job carries on. On the script's last line, though, a failure before && becomes the script's exit code, so a false test such as test -f file && ./deploy.sh fails the job with exit code 1: write it as an if statement instead. To make a failure before && stop the job on any line, set the runner feature flag FF_ENABLE_BASH_EXIT_CODE_CHECK to true; then every false test before && fails the job, so turn those into if statements first.
How do I let a GitLab job pass when it exits with code 1?
Where 1 is a normal result, add || true to that command, or save its code with status=0; command || status=$? and decide yourself. To let the job fail without failing the pipeline, set allow_failure: exit_codes: 1: the job shows a warning, the pipeline carries on, and any other exit code still fails it.
Sources
- GitLab docs — Ignore non-zero exit codes
- GitLab docs — allow_failure:exit_codes
- GitLab docs — Enable debug logging
- GitLab Runner docs — Feature flags
- GitLab Runner source — how the bash script runs (bash.go)
Checked against these pages on 15 November 2026. GitLab changes quickly — if something here no longer matches, tell us and we will fix it.
Do this from your phone with MergeBell
Free for the whole review loop: the To-Do inbox, diffs and line comments, approve and merge, pipelines with retry, and push alerts for your To-Dos. Works with gitlab.com and self-managed GitLab 16.0+.
Get MergeBell for iPhoneGet MergeBell for Android
On the App Store for iOS 26 or later and on Google Play for Android 12 or later. An independent app, not affiliated with GitLab Inc.