1. The discipline of continuous integration #
More than a build server.
The rules #
- Everyone integrates into the main branch at least once a day.
- Every integration triggers an automatic build and tests.
- The build is fast: less than 10 minutes for the commit stage.
- A broken build is fixed immediately, taking priority over everything else.
- Everyone can see the build status and get the latest artifact.
Key takeaway: Having Jenkins or GitHub Actions is not enough: branches that live three weeks without integration are not continuous integration, even with a pipeline.
2. Tests #
The safety net of CI/CD.
The pyramid #
| Type | Checks | Tools (examples) |
|---|---|---|
| Unit | an isolated function or class | pytest, JUnit, Jest, go test |
| Integration | the code with a real database, a real queue | Testcontainers, docker compose |
| Contract | that an API provider meets what its consumers expect | Pact, OpenAPI schemas |
| End-to-end | a complete user journey | Playwright, Cypress |
| Performance | response times and behavior under load | k6, Gatling |
| Security | code, dependencies, images | Semgrep, Trivy, OWASP ZAP |
Realistic integration tests #
# pytest + Testcontainers : une vraie base PostgreSQL éphémère pour chaque exécution
from testcontainers.postgres import PostgresContainer
import psycopg
def test_insertion_commande():
with PostgresContainer("postgres:16") as pg:
with psycopg.connect(pg.get_connection_url().replace("+psycopg2", "")) as conn:
conn.execute("CREATE TABLE commandes (id serial, total numeric)")
conn.execute("INSERT INTO commandes (total) VALUES (42)")
assert conn.execute("SELECT count(*) FROM commandes").fetchone()[0] == 1Flaky tests #
A test that fails « sometimes » destroys trust: the team reruns the pipeline without reading the error, and ends up ignoring a real problem.
Good practice: Quarantine a flaky test (marked, non-blocking) with a ticket, fix it quickly (explicit waits, isolated data, mocked clock) and track the pipeline rerun rate.
3. Quality and quality gates #
Automatic rules, not debates in review.
Static analysis #
ruff check . && ruff format --check . # Python : lint et formatage
mypy src/ # typage
eslint . && prettier --check . # JavaScript
hadolint Dockerfile # bonnes pratiques Dockerfile
shellcheck scripts/*.sh
gitleaks detect --source . # secrets commitésQuality gate #
A quality gate is a set of blocking conditions (SonarQube, branch protection rules). Measure coverage of new code rather than a global percentage: requiring 80% on a codebase at 30% blocks everything and pushes people to write hollow tests.
Common mistake: Coverage measures the code executed by tests, not the quality of the assertions: a test without assertions « covers » code without checking anything.
4. A fast pipeline #
Keeping feedback under 10 minutes.
Techniques #
| Technique | Effect |
|---|---|
| Dependency cache | avoids re-downloading at each build |
| Parallelizing and splitting tests | divides duration by the number of runners |
| Matrix | tests several versions (language, OS) in parallel |
| Selective execution | run only what is affected (monorepo: changed paths) |
| Docker layer cache | rebuilds only changed layers |
| Cancelling obsolete builds | a new push cancels the previous pipeline of the same branch |
jobs:
test:
strategy:
matrix:
python: ["3.11", "3.12", "3.13"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: "${{ matrix.python }}", cache: pip }
- run: pip install -r requirements.txt && pytest -q -n auto # pytest-xdist
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: trueMy 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
End-to-end CI/CD (1/5): principles and anatomy of a pipeline
Understand end-to-end CI/CD: continuous integration, continuous delivery and continuous deploymen...
k6 in continuous integration and on Kubernetes (k6-operator)
Automate performance tests: k6 in GitHub Actions and GitLab CI with blocking thresholds, distribu...
End-to-end CI/CD (3/5): artifacts, registries and environments
Deliver continuously: immutable, versioned artifacts, image and package registries, promoting the...
End-to-end CI/CD (4/5): deployment strategies and rollback
Deploy without downtime and without risk: recreate, rolling update, blue/green, canary, feature f...
DevOps best practices: culture, CI/CD, infrastructure as code and measurement
DevOps best practices: culture and collaboration, continuous integration and delivery, trunk-base...
Ansible: going further (testing, quality, CI/CD and performance)
Industrialize Ansible: ansible-lint, yamllint, Molecule, continuous integration, collections, exe...
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...
Measuring DevOps performance: DORA metrics, SPACE and continuous improvement
Measure and improve delivery performance: the DORA metrics (deployment frequency, lead time, chan...
Testing and securing Terraform: validate, terraform test, tflint, Checkov and policies
Ensure the quality of Terraform code: fmt and validate, native terraform test tests with mocked p...