GitLab CI before_script Fails - Whole Job Aborts Before script
GitLab concatenates before_script and script into one shell run. If any before_script line exits non-zero, the job fails there and your script never executes.
What this error means
The job fails during setup - installing a tool, configuring auth, or sourcing an env - and your main script output never appears. The failing command is in before_script (or a default:before_script).
$ apt-get install -y somecli
E: Unable to locate package somecli
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 100Common causes
A setup command fails
Installing a package, logging into a registry, or generating config in before_script returns non-zero, and GitLab stops the job immediately.
Inherited default:before_script breaks
A global default:before_script (or one from an include/extends) runs before every job. A change there can break jobs that never declared a before_script themselves.
How to fix it
Fix or guard the setup step
Make setup commands robust and idempotent so they do not fail the whole job.
before_script:
- apt-get update
- apt-get install -y curl jq
- command -v aws >/dev/null || pip install awscliIsolate where it failed
- Note that
before_scriptruns in the same shell asscript- the failing line is in the setup block. - Check whether a global
default:before_scriptor an included template is the source. - Override
before_script: []in a job to opt out of an inherited setup that does not apply.
How to prevent it
- Keep
before_scriptminimal, idempotent, and non-interactive. - Pin tool versions so setup does not break on upstream changes.
- Test changes to shared
default:before_scriptagainst multiple jobs.