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
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...
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 (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 (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...
DevSecOps: securing the software supply chain end to end
Integrate security into the DevOps pipeline: shift-left, threat modeling, secret detection, SAST,...
Measuring DevOps performance: DORA metrics, SPACE and continuous improvement
Measure and improve delivery performance: the DORA metrics (deployment frequency, lead time, chan...
Observability, SRE and incident management for DevOps teams
Operate what you ship: metrics, logs and traces, golden signals, SLIs, SLOs and error budgets, ac...
Git for DevOps: branches, code reviews and versions
Organize work with Git in a DevOps approach: trunk-based development or GitFlow, short-lived bran...