Skip to content

Lesson 1 of 9 · 20m

The Pipeline Mental Model: Jobs, Stages, and State

What GitLab actually schedules, why stage order is only half the story, and how to read a broken pipeline before touching the YAML.

GitLab CI looks simple because the YAML is small. Then production hits: a job starts before its dependency finishes, artifacts vanish, and three people rerun the same pipeline because nobody can tell whether the failure is in the job, the runner, or the dependency graph. The mental model is the difference between guessing and operating.

A pipeline is a scheduling problem

A pipeline is a set of jobs with inputs, outputs, rules, and constraints. GitLab turns your .gitlab-ci.yml into a graph, then hands eligible jobs to runners. It does not "run the file" top to bottom.

stages: [test, build, deploy]

test:
  stage: test
  script:
    - bundle exec rspec

build-image:
  stage: build
  script:
    - docker build -t registry.example.com/platform/app:$CI_COMMIT_SHA .

deploy:
  stage: deploy
  script:
    - ./deploy/production
  environment: production

Within one stage, jobs start in parallel as soon as runners are available. Across stages, a later stage normally waits for every job in the previous stage to succeed. That is the default, not the ceiling.

Jobs are isolated executions

Each job gets a fresh workspace unless your runner configuration or cache says otherwise. Do not assume the shell state, downloaded files, package installs, or even the working directory contents survive into another job. The explicit handoff mechanisms are artifacts and cache.

Use artifacts for outputs produced by this pipeline and cache for reusable dependency data across pipelines. If you mix them up, you get jobs that are fast until they are wrong.

Status is not the same as outcome

A pipeline can be green and still useless. A deploy job can pass while deploying the wrong commit because $CI_COMMIT_SHA was ignored. A security job can pass because its allow_failure flag hid the finding. Read the job traces and variable context, not just the status badge.

Useful debugging path:

  1. Open the pipeline graph and identify what actually ran.
  2. Open the failing job log and find the first error, not the final shell exit.
  3. Compare variables and image versions with the last known-good run.
  4. Check whether the same job ran on a different runner.

Field notes

  • A pipeline is dataflow plus scheduling, not a shell script with pretty indentation.
  • needs makes dependencies explicit; stage order alone is a coarse default.
  • Artifact paths are relative to the project directory, not wherever your script happened to cd last.
  • Rerunning a failed job reuses the same commit but not the same time, runner, or external world.
  • If a job passes locally but fails in CI, suspect environment difference first and code second.

Was this lesson helpful?

Sign in to rate