1. CI, CD and CD #
Three practices, often confused.
Definitions #
| Practice | Definition | Condition |
|---|---|---|
| Continuous integration (CI) | every change is integrated into the main branch, built and tested automatically, several times a day | fast automated tests, short-lived branches |
| Continuous Delivery | every version that passes the pipeline is deployable to production at any time, in one click | automated, reproducible deployment |
| Continuous Deployment | every version that passes the pipeline goes to production automatically | full confidence in the tests, progressive deployments, automatic rollback |
CI answers « does my code integrate with everyone else's? », continuous delivery « can I ship now? », continuous deployment removes the question.
Why it pays off #
- Smaller batches: each deployment changes little, so it breaks little and is diagnosed quickly.
- Fast feedback: a developer learns within minutes that they broke something, not weeks later.
- A reproducible process: releasing to production becomes a non-event.
- Better DORA metrics: deployment frequency, lead time, change failure rate and time to restore.
2. Anatomy of a pipeline #
The stages from commit to production.
The stages #
| Stage | Content | Target duration |
|---|---|---|
| Commit stage | compilation, unit tests, lint, static analysis, secret detection | < 10 min |
| Package | building a single, versioned artifact (image, binary, package) | a few minutes |
| Acceptance tests | integration and end-to-end tests on an ephemeral or staging environment | < 30 min |
| Deployment | promoting the same artifact to staging then production | minutes |
| Verification | smoke tests, metric analysis, automatic rollback on degradation | minutes |
The technical building blocks #
| Notion | Role |
|---|---|
| Trigger | push, pull request, tag, schedule, manual trigger |
| Runner / agent | machine (often an ephemeral container) that runs the jobs |
| Job / step | unit of work; jobs in the same stage run in parallel |
| Cache | dependencies reused from one build to the next to save time |
| Artifact | output produced by a job and passed to the next ones or published |
| Environment | deployment target (staging, production) with its secrets and approval rules |
| Secrets | credentials injected at run time, never written into the repository |
3. Fundamental principles #
What makes a pipeline reliable.
Build once, deploy many #
The artifact is built only once, given an immutable version (the commit SHA), and it is that same artifact that is tested and then promoted from staging to production. Rebuilding for production means deploying something that has never been tested.
Common mistake: An image tagged latest or rebuilt per environment breaks traceability: there is no way to know exactly what is running in production or to go back to the previous version.The other rules #
- Pipeline as code: the pipeline definition is versioned with the code (
.github/workflows,.gitlab-ci.yml,Jenkinsfile). - Fail fast: quick checks first, the longest ones afterwards.
- A red pipeline takes priority: fix it (or revert the commit) before going further.
- External configuration: the artifact is identical everywhere, only the configuration changes (variables, secrets, 12 factors).
- Reproducibility: pinned tool and dependency versions, ephemeral runners.
- Everything goes through the pipeline, including urgent fixes: otherwise the pipeline stops being the source of truth.
4. A first pipeline #
The same logic with two tools.
GitHub Actions #
# .github/workflows/ci.yml
name: ci
on:
push: { branches: [main] }
pull_request: {}
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: "3.12", cache: pip }
- run: pip install -r requirements.txt
- run: pytest -q
build:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker build -t app:${{ github.sha }} .GitLab CI #
# .gitlab-ci.yml
stages: [test, build]
test:
stage: test
image: python:3.12
script:
- pip install -r requirements.txt
- pytest -q
build:
stage: build
image: docker:27
services: [docker:27-dind]
rules: [{ if: '$CI_COMMIT_BRANCH == "main"' }]
script:
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .Rest of the chapter: The next four lessons detail each part: continuous integration and testing, artifacts and environments, deployment strategies, then tools.
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
Terraform: principles, architecture and workflow
Understand Terraform: declarative infrastructure as code, architecture (core, providers, state), ...
Infrastructure as Code and GitOps: Terraform, Ansible and Argo CD
Manage infrastructure as code: declarative or imperative, Terraform (providers, state, plan, modu...
Platform engineering, FinOps and AI: the new frontiers of DevOps
Understand how DevOps is evolving: platform engineering and internal developer platforms (IDP), g...
k6 in continuous integration and on Kubernetes (k6-operator)
Automate performance tests: k6 in GitHub Actions and GitLab CI with blocking thresholds, distribu...
DevOps variants: understanding how engineering culture has evolved
Discover the different flavors of DevOps: DevSecOps, AIOps, NoOps, GitOps and FinOps. Understand ...
Organizing DevOps: value streams, teams and a blameless culture
Set up a DevOps organization: value chain and value stream mapping, Team Topologies, « you build ...
The wall of confusion
The 'wall of confusion' is a metaphor often used in a DevOps context to describe the cultural, or...
The CALMS framework: the 5 pillars of DevOps
Discover the CALMS framework, the essential foundation for a successful DevOps transformation, th...
Chaos engineering: principles, tools and practice with SLOs
A complete guide to chaos engineering: principles, steady state and hypothesis, blast radius, lin...