CI/CD · Ship safely, repeatedly

How does GitLab CI structure a pipeline?

Mediumgitlab cipipelinedagUpdated Oct 2026
Quiz this track

Short answer

GitLab CI uses .gitlab-ci.yml with stages and jobs. Jobs in the same stage run in parallel, needs creates a directed acyclic graph, and artifacts and cache move data between jobs.

Stages define the default order, while needs lets a job start as soon as its specific dependencies finish instead of waiting for an entire stage. That DAG behaviour is what makes larger pipelines fast.

  • stages controls the default execution order of jobs
  • needs creates explicit dependencies and enables out-of-order execution
  • artifacts are files passed to later jobs; cache is reused across pipeline runs
  • rules decides whether a job is added to the pipeline
  • environment records deployments and enables protected environments
  • include and extends support shared templates and job inheritance
yaml
stages:
  - test
  - package
  - deploy

unit:
  stage: test
  script:
    - npm ci
    - npm test

image:
  stage: package
  needs: [unit]
  script:
    - docker build -t registry.example.com/app:1.8.3 .
    - docker push registry.example.com/app:1.8.3
Do not use cache for artifacts that must be exact. Cache is a best-effort optimization. Artifacts are the explicit handoff between jobs in a pipeline.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What is the difference between cache and artifacts in GitLab CI?
  2. 2How does needs change execution order?
  3. 3How do you prevent a deploy job from running on a feature branch?
  4. 4What are protected environments?

Say it in the interview

GitLab CI defines stages and jobs in the GitLab CI configuration. Jobs in the same stage run in parallel, and needs lets a job depend on specific earlier jobs rather than a whole stage, which shortens the critical path. Artifacts move required files between jobs, while cache is a best-effort speed optimization. I use rules to control when jobs are added and protected environments for production deploys.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live CI/CD mock interview and get scored feedback on depth, clarity and confidence.