Introduction to CI/CD
Table of contents
- CI/CD definitions
- Continuous Integration (CI)
- Continuous Delivery (CD)
- Continuous Deployment
- Anatomy of a pipeline
- Best practices
1 - CI/CD definitions
Overview
The three concepts
| Concept | Definition | Automation |
|---|---|---|
| CI | Frequent integration of code | Build + Tests |
| Continuous Delivery | Ready to deploy at any time | + Release |
| Continuous Deployment | Automatic deployment | + Production |
The difference between Continuous Delivery and Continuous Deployment is a manual validation: Delivery waits for an approval, Deployment is fully automatic.
🔝 Back to table of contents
2 - Continuous Integration (CI)
The problem without CI
The CI solution
The rules of CI
| Rule | Description |
|---|---|
| Frequent commits | At least once a day |
| Automatic build | Triggered on every commit |
| Automatic tests | Unit + Integration |
| Fast feedback | < 10 minutes ideally |
| Immediate fix | Broken build = priority #1 |
A broken build blocks the whole team. Fixing it is the absolute priority. No "I'll get to it later".
Typical CI pipeline
Benefits of CI
- Early bug detection
- Fewer merge conflicts
- Code always in a deployable state
- Fast feedback to developers
- Confidence in the code
🔝 Back to table of contents
3 - Continuous Delivery (CD)
Extension of CI
Continuous delivery extends CI by ensuring the code can be deployed at any time.
Environments
| Environment | Usage |
|---|---|
| Development | Local tests, experimentation |
| Testing/QA | Automated tests, validation |
| Staging | Mirror of production, final tests |
| Production | Real users |
Key practices
- Identical deployments: same process for all environments
- Externalized configuration: environment variables
- Database migrations: versioned and automated
- Feature flags: enable/disable features
🔝 Back to table of contents
4 - Continuous Deployment
Beyond delivery
Continuous deployment removes the manual validation: every validated change goes automatically to production.
Prerequisites
| Prerequisite | Reason |
|---|---|
| Exhaustive tests | Safety net |
| Robust monitoring | Fast detection |
| Automatic rollback | Fast recovery |
| Feature flags | Exposure control |
| Quality culture | Shared responsibility |
Continuous deployment without exhaustive tests is a recipe for disaster. Make sure you have sufficient test coverage before implementing it.
Comparison of approaches
🔝 Back to table of contents
5 - Anatomy of a pipeline
Structure of a pipeline
Example pipeline file
GitHub Actions:
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm run build
test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm test
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to production
run: echo "Deploying..."
Parallel vs sequential jobs
Parallelize independent jobs to reduce the total pipeline time.
Artifacts and cache
| Concept | Usage |
|---|---|
| Artifact | Result of a job (JAR, Docker image) |
| Cache | Reusable dependencies (node_modules) |
| Workspace | Files shared between jobs |
🔝 Back to table of contents
6 - Best practices
The 10 CI/CD commandments
| # | Practice |
|---|---|
| 1 | Maintain a single source repository |
| 2 | Automate the build |
| 3 | Make the build self-testing |
| 4 | Commit frequently to mainline |
| 5 | Build on every commit |
| 6 | Keep the build fast |
| 7 | Test in a clone of production |
| 8 | Make artifacts accessible |
| 9 | Visibility into the process |
| 10 | Automate deployment |
Fast pipeline
Goal: feedback in under 10 minutes. Beyond that, developers lose the context of their change.
Trunk-based development
Recommended practice:
- Short-lived branches (< 1 day)
- Frequent merges to main
- Feature flags for incomplete code
Secrets management
| Method | Example |
|---|---|
| Environment variables | GitHub Secrets |
| Vault | HashiCorp Vault |
| Cloud KMS | AWS Secrets Manager |
Never commit secrets into the code. Always use environment variables or a secrets manager.
🔝 Back to table of contents
Key takeaways
- CI: frequent integration with automatic build and tests
- Continuous Delivery: ready to deploy, manual validation
- Continuous Deployment: automatic deployment to production
- A fast pipeline (< 10 min) is essential
- Automated tests are the safety net
- Feature flags let you decouple deployment from release