Job Scripts and Commands
You'll learn: How to write multi-line scripts and shell commands inside GitLab CI jobs, and understand how GitLab executes them.
What Are Job Scripts?
In GitLab CI, the script keyword is where you tell your pipeline what to actually do. Think of it like writing a to-do list for a robot—each command runs in sequence on the runner, just as if you typed them in a terminal yourself. The script section is mandatory for every job.
Writing Scripts
GitLab lets you write single-line or multi-line scripts using YAML list syntax:
build-app:
stage: build
script:
- echo "Starting build process"
- npm install
- npm run build
- echo "Build complete"
Each line (prefixed with -) is a separate shell command. If any command fails (returns a non-zero exit code), the entire job fails immediately and stops executing further commands.
How Script Execution Works
Behind the scenes, GitLab bundles your script commands into a temporary shell script file and executes it on the runner. By default, it uses /bin/bash on Linux runners. The job runs in a clean environment each time—no state persists between jobs unless you explicitly pass artifacts or use caching.
You can use normal shell features like variables, pipes, and conditionals:
test-app:
stage: test
script:
- export TEST_ENV=production
- npm test | grep -i "passed"
Key Takeaway: The script section contains the shell commands your job executes sequentially; if any command fails, the job stops and marks as failed, making it critical to order commands thoughtfully.