1. A complete pipeline #
Lint, tests, build.
The file #
stages: [lint, test, build]
default:
image: python:3.12-slim
interruptible: true
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
lint:
stage: lint
script: python -m compileall -q .
test:
stage: test
cache:
key:
files: [requirements-dev.txt]
paths: [.cache/pip]
script:
- pip install -r requirements-dev.txt
- pytest --junitxml=rapport.xml
artifacts:
when: always
reports:
junit: rapport.xml
build:
stage: build
needs: [test]
script: tar czf boutique-$CI_COMMIT_SHORT_SHA.tar.gz app.py Dockerfile
artifacts:
paths: [boutique-*.tar.gz]
expire_in: 1 week
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCHdefaultsets the image and shared settings;variablesdefines global variables.workflow:rulesdecides whether a pipeline is created: here, a merge request pipeline, and no duplicate branch pipeline.needsstarts a job as soon as its dependencies finish, without waiting for the whole stage (directed acyclic graph, DAG).
2. Rules and conditions #
Running the right job at the right time.
rules #
| Clause | Example | Use |
|---|---|---|
| if | $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH | condition on variables |
| changes | [src/**/*, Dockerfile] | only if these files changed |
| exists | [Dockerfile] | only if a file exists |
| when | manual, delayed, never, on_failure | trigger mode |
Watch out :only/exceptare deprecated: userules, clearer and more powerful. Rules are evaluated in order and the first match wins.
3. Cache, artifacts and parallelism #
Going fast without mistakes.
Cache or artifact? #
| Criterion | cache | artifacts |
|---|---|---|
| Purpose | speed up (downloaded dependencies) | pass a result between jobs or keep it |
| Guarantee | best effort: may be missing | always available to later jobs |
| Examples | .cache/pip, node_modules | binary, JUnit report, coverage |
test:
parallel:
matrix:
- PYTHON: ["3.12", "3.13"]
image: python:$PYTHON-slim
script: [pip install -r requirements-dev.txt, pytest]
retry: { max: 2, when: [runner_system_failure, stuck_or_timeout_failure] }
timeout: 15mBest practice : Only retry infrastructure failures automatically: retrying a flaky test hides the problem instead of fixing it.
Commands to know #
Commands to know
glab ci lint --dry-run --ref main: simulate pipeline creationglab ci run -b main: run a pipelineglab ci retry <job-id>: retry a jobglab ci artifact main build: download artifacts
Sources #
Checked in November 2026: CI/CD platforms change every month, check versions and plans in the vendor's documentation.
My progress
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Recommended Articles
Writing GitHub Actions workflows
Mastering workflow syntax: triggers and filters, jobs and needs, matrices, if conditions, context...
GitLab CI/CD: concepts and architecture
Discover GitLab CI/CD: the DevSecOps platform, the .gitlab-ci.yml file, pipelines, stages and job...
GitLab runners: types, executors, installation and security
Running GitLab jobs: instance, group and project runners, docker, kubernetes and docker-autoscale...
Azure YAML pipelines: stages, tasks, variables and templates
Writing Azure pipelines in YAML: trigger and pr triggers, stages, jobs and steps, versioned tasks...
Building and delivering with GitLab: registry, environments and deployments
Delivering with GitLab CI/CD: building and publishing images to the project registry, package reg...
Reusing and securing GitLab pipelines
Industrializing GitLab CI/CD: extends, anchors and !reference, include, CI/CD components and cata...
GitLab CI/CD best practices and troubleshooting
Running GitLab CI/CD day to day: speeding up pipelines, controlling compute minutes, organizing f...
End-to-end CI/CD (5/5): GitHub Actions, GitLab CI, Jenkins and Argo CD in practice
Compare and use CI/CD tools: GitHub Actions, GitLab CI, Jenkins, Argo CD and Flux; a complete pip...
End-to-end CI/CD (2/5): continuous integration, testing and quality
Succeed with continuous integration: the test pyramid, unit, integration, contract and end-to-end...