Sub topic 1
Why teams need CI/CD
CI/CD is a set of practices and tooling that builds, tests, and releases software automatically every time the code changes. This chapter explains the problems that motivated it. Later chapters cover how each part works.
Prerequisites
This chapter assumes you have:
- Basic Git usage: commits, branches, and pull requests.
- Experience building and running tests for a small application.
- Basic command-line use.
- Enough YAML to read a short configuration file.
You do not need to have used a CI/CD tool before.
The problem: getting code from a laptop to users
Writing code is only part of delivering software. The change must also be combined with other people's work, verified, packaged, and installed somewhere users can reach it. Each of these steps can go wrong, and when people do them by hand, they go wrong in predictable ways.
Consider a team of six developers without automation. Each works on a branch for two or three weeks. A release is planned for the end of the month. The steps look like this:
- Everyone merges their branches into one release branch.
- Someone builds the application on their own machine.
- A tester runs through the application by hand for a few days.
- An operations engineer follows a checklist to copy the build to a server, usually late at night.
Almost every pain point in this process maps to something CI/CD addresses.
Pain point 1: integration happens too late
When branches live for weeks, they drift apart. Two developers may change the same function, rename the same file, or make assumptions that contradict each other. Git can report textual conflicts, but it cannot tell you that one branch now calls a function that another branch removed. Those semantic conflicts surface only when the merged code is built and run.
If the merge happens once a month, the team discovers all of these problems at once, close to the release date. This is often called "merge hell". The cost of fixing a defect also grows with the time since it was introduced. The author has forgotten the details, and other work now depends on the broken change.
The CI answer is to merge small changes to a shared branch often, at least daily, and to verify each merge automatically. Problems then appear within minutes, while the author still remembers the change.
Pain point 2: "it works on my machine"
A build made on a developer's laptop depends on that laptop. It depends on the installed language version, the operating system, locally cached dependencies, environment variables, and sometimes uncommitted files. Two people building the same commit can get different results.
This causes two failures:
- A change passes locally but fails elsewhere, so nobody can tell whether the code or the environment is at fault.
- A release is built by one person on one machine, and nobody can reproduce it later when a bug needs to be investigated.
A CI server builds from a clean, defined environment every time. The build instructions live in the repository, so the result depends on the commit and not on whoever ran it.
Pain point 3: manual verification does not scale
Manual testing is slow and inconsistent. A tester who has checked the same screens many times will eventually skip a step. Manual testing also takes longer as the application grows, so teams run it less often, which lets defects pile up between runs.
Automated tests run the same checks identically every time. They are also cheap to repeat. Running them on every change turns testing from a phase near the end into continuous feedback.
Automation has limits. A test suite only checks what its authors wrote tests for, and a passing run does not prove the software is correct. It proves that no known check failed. Exploratory testing by people still has value. The aim is to remove repetitive checking from people so they can spend time on judgment.
Pain point 4: releases are slow, risky, and stressful
Manual releases tend to be rare because they are painful. Rare releases then become larger, because more changes accumulate between them. Larger releases carry more risk, which makes the team more nervous, which makes them even rarer. This is a self-reinforcing loop.
Large releases are hard to debug for a specific reason. If one release contains 200 changes and something breaks, any of the 200 could be responsible. If a release contains one change, the cause is almost always that change.
Manual deployment steps add a separate problem. A checklist followed by a person at midnight can be performed slightly differently each time. Skipped steps, typos in commands, and forgotten configuration changes are common causes of outages.
CI/CD breaks the loop from the other side. Making each release cheap and repeatable lets the team release more often. Smaller releases are less risky, so the fear that kept releases rare fades.
Pain point 5: knowledge lives in people's heads
In a manual process, the real build and release procedure is often known by one or two people. If they are on leave, nobody can release. Documentation tends to be out of date, because the real procedure changes and the document does not.
Automated pipelines are executable documentation. The definition of how to build, test, and deploy sits in version control, can be reviewed in a pull request, and is the process the team actually runs.
What CI/CD means
The term "CI/CD" covers three related practices. The next chapters treat each in depth, so here are short definitions.
| Practice | What it does | Who triggers the release |
|---|---|---|
| Continuous integration (CI) | Merges changes often and builds and tests every one automatically | Not applicable. It stops at verified code |
| Continuous delivery | Keeps every verified change in a releasable state, with deployment ready to run | A person decides, usually with one approval |
| Continuous deployment | Deploys every change that passes the pipeline, with no human step | The pipeline itself |
People often use "CD" for either of the last two, so check which one a team means. The difference is whether a human approves the final step.
A concrete example
Here is a minimal GitHub Actions workflow. Every push to main and every pull request starts a clean build, installs dependencies, and runs the tests.
name: ci
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm testThis small file addresses several of the pain points above:
- The
onblock runs the checks on every change, so integration problems appear within minutes. runs-on: ubuntu-latestprovides a fresh machine each time, which removes dependence on any one laptop.node-version: 20pins the runtime, so the environment is defined in the repository.npm ciinstalls exactly the versions recorded in the lockfile, which keeps dependencies reproducible.npm testreplaces a manual check with an automated one.
The workflow only verifies code. It does not yet package or deploy anything. Later chapters extend it.
What CI/CD costs and what it does not fix
CI/CD is not free, and it does not solve every problem.
- Setup and upkeep. Pipelines are code. They need maintenance, and a slow or flaky pipeline erodes the team's trust and can be worse than none.
- Test quality. A pipeline running weak tests gives false confidence. Automation speeds up feedback, but it does not make the feedback correct.
- Team habits. Merging daily requires small changes and a working branch policy. Installing a CI tool while keeping three-week branches gains little.
- Infrastructure and security. Pipelines hold credentials and can change production, so they become a target. A later chapter covers this.
Whether the investment pays off depends on how often you ship. A personal script released twice a year may not need a full pipeline. A team shipping weekly or daily almost certainly does.
Summary of the problems and responses
| Problem | Typical symptom | CI/CD response |
|---|---|---|
| Late integration | Large merge conflicts before release | Frequent merges verified automatically |
| Environment differences | "Works on my machine" | Builds on clean, defined machines |
| Manual testing | Skipped checks, slow feedback | Automated tests on every change |
| Large, rare releases | Hard to find the cause of a failure | Small, frequent, repeatable releases |
| Knowledge in heads | Only one person can release | Pipeline definition stored in version control |
Exercise
A team merges branches once a month, builds on a lead developer's laptop, and deploys by following a wiki checklist. List three specific problems this causes, and for each name the CI/CD practice that addresses it.
Show answer
Any three of the following. (1) Late integration causes large conflicts and defects found near release time. Frequent merges with an automated build and test run on every change address this. (2) Builds on one laptop depend on that machine and cannot be reproduced. A CI server building from a clean, defined environment addresses this. (3) A hand-followed checklist is performed inconsistently and may be out of date. A deployment script in a pipeline stored in version control addresses this. (4) Monthly releases are large, so failures are hard to trace. Smaller, more frequent releases address this.
Exercise
In the example workflow, which line makes sure dependencies match the versions recorded in the lockfile, and why does that matter for the "works on my machine" problem?
Show answer
The line run: npm ci does this. It installs exactly the versions in the lockfile instead of resolving new ones, so the CI run and a developer's machine use the same dependencies. This removes one common cause of results that differ between machines.