What is CI/CD?
CI/CD is an automated pipeline where continuous integration builds and tests every change and continuous delivery or deployment ships it to your servers.
- Updated Nov 27, 2026
- Markdown
Explain CI and CD and add a small pipeline that runs your tests on every push.
- A code repository on a host that offers pipelines, such as GitHub
From a push to a running app
- You push a change to the repository.
- The push triggers the CI pipeline automatically.
- CI builds the code and runs the tests, and stops if any fail.
- When the tests pass, the build is published as an image.
- The delivery step pulls the new image onto your server.
- The change is running, with no manual copying.
Static diagram
- YoupushRepository
- RepositorytriggerCI
- CItests passRepository
- CIpublishRegistry
- RegistrydeployYour server
- Your serverliveYou
You fix a typo, copy files to the server by hand, and forget a build step. The site breaks, and nobody remembers exactly what was copied. CI/CD replaces manual, error-prone release steps with a repeatable script that runs on every change.
How it works#
A pipeline is a script that your code host runs for you, on a machine called a runner, every time something happens (usually a push or a pull request). The runner starts clean, so it cannot depend on anything that only exists on your laptop. That is the point: if the build works there, it works for everyone.
Continuous integration (CI) is the first half. Each time someone pushes code, the runner checks it out, installs dependencies, builds it and runs the tests. If something fails, you hear about it within minutes, while the change is still small.
Continuous delivery and deployment (CD) is the second half. After CI passes, the pipeline can deliver the result:
- Continuous delivery: the build is ready to release, and a person approves the deploy.
- Continuous deployment: every passing change goes live with no manual step.
A pipeline is a list of stages that run in order, and a failure stops the rest:
- Checkout the code.
- Build.
- Test.
- Package, for example a Docker image pushed to a registry.
- Deploy, for example by logging in over SSH and running
docker compose pull && docker compose up -d.
A tiny example#
Many hosts use a YAML file. This one, in the GitHub Actions style, runs tests on every push:
name: ci
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm teston: push is the trigger. runs-on picks the runner image. Each steps entry runs in order, and a non-zero exit code from any step fails the job. npm ci installs exactly what the lockfile says. Other tools use different file names and keys, but the idea is the same.
To limit overlapping deploys, add a concurrency group to the job that deploys:
concurrency:
group: deploy-production
cancel-in-progress: falseWith cancel-in-progress: false, a second run waits instead of cancelling the first.
Check it worked#
Push a small change. In your code host you should see the pipeline start and finish with a green status. Then push a deliberately failing test and confirm the pipeline turns red and stops before any deploy stage. Revert the failing test afterwards.
You can also run the same commands locally to see what the runner will do:
npm ci && npm test; echo "exit code: $?"The last line prints exit code: 0 when the pipeline’s test stage would pass.
Edge cases and gotchas#
- It works on my machine, fails in CI. The runner starts clean. Missing environment variables, files ignored by git, or a different Node or Go version are the usual causes. Pin versions in the workflow.
- Secrets do not reach pull requests from forks. Most hosts withhold secrets from fork builds on purpose, so a deploy or integration test needing them is skipped or fails there.
- Secrets can leak through logs. A
set -xor anechoof an environment variable can print a secret. Hosts mask known secrets, but not transformed values, so never print them. - Deploy races. Two quick pushes can run two deploys at once, and the older one may finish last. Use a concurrency setting so only one runs.
- Architecture mismatch. An image built on an amd64 runner will not run on an ARM server. Build for the architecture your server uses.
- The deploy key is a risk. If the pipeline can SSH into your server, anyone who can change the workflow can run commands there. Protect the branch and use a key limited to the deploy user.
- Green does not mean healthy. Tests can pass while production config is wrong. End the pipeline with a check against your real health URL.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| Pipeline never starts | Workflow file in the wrong folder or invalid YAML | Check the path your host requires and validate the YAML |
Permission denied (publickey) in the deploy step | Wrong or missing SSH key in the secret store | Add the private key as a secret and the public key to the server |
| Tests pass locally, fail in CI | Different versions or missing env vars | Pin versions, set variables in the workflow |
exec format error when the container starts | Image built for another CPU architecture | Build for the server’s architecture |
| Deploy step succeeds but old version is live | Server did not pull the new image or tag | Use a unique tag per build and pull it explicitly |
Secret value shows as *** in logs | The host masked it | Expected; do not try to print it |
| Two deploys overlap | No concurrency control | Add a concurrency group |
| Pipeline is slow | Dependencies are downloaded each run | Cache dependencies using your host’s cache feature |
| Deploy runs on every branch | Trigger is too broad | Limit the deploy job to the main branch |
Real-world scenario#
Two people work on a small API. Before CI, a release meant SSH, git pull, and hoping the build still worked. One Friday a missing dependency in the lockfile took the site down for an hour.
They add the workflow above and a deploy job that only runs on the main branch after tests pass. The next time someone forgets to commit the lockfile, npm ci fails on the runner within a minute, the job turns red, and nothing reaches the server. The fix is a one-line commit.
The deploy job then logs in over SSH and runs:
docker compose pull && docker compose up -d
curl -fsS https://example.com/healthThe final curl fails the pipeline if the app does not answer, so a broken release is noticed by the pipeline and not by customers.
Quick reference#
| Term | Meaning |
|---|---|
| Runner | The machine that runs the pipeline |
| Trigger | Event that starts it, such as on: push |
| Stage or job | One step group, run in order |
| Artifact | Output kept between jobs, such as a built image |
| Secret | Value stored by the host, read at run time |
| Gate | A manual approval or a passing check before deploy |
Security and safety notes#
- Never commit tokens or keys into the workflow file. Use the secret store.
- Do not give the deploy key more rights than needed. A full-access root key on the server is a large target.
- Keep a way to go back: see Rollbacks.
Related lessons#
Next#
Decide how new versions replace old ones: Blue-green vs rolling deploys.
Check what you learned
Frequently asked questions
What is the difference between CI and CD?
CI builds and tests each change as it is pushed. CD takes a change that passed and delivers it to an environment, either after a manual approval or automatically.
Do I need CI/CD for a small project?
No, but even a single automated test run on each push catches mistakes early and costs little to set up.
Why does the pipeline pass but my deploy still breaks?
A pipeline only checks what you told it to check. Tests may skip real config, secrets, or the production database, so add a health check after deploy.
Can the pipeline log in to my server?
Yes, usually with an SSH key stored in the pipeline's secret store. Give that key only the access the deploy needs.
Keep going: guides and tutorials
- Zero Downtime Deploy for Docker Apps, With Rollback How a Docker deploy waits for readiness before cutover, holds the previous release for rollback, rolls back on its own, and how to rehearse it.
- Roll Back a Failed Docker Deploy Without Downtime Ship a broken release on purpose, watch your users stay on the old version, then roll back with one command. Real commands, real output, self-hosted.
- Our Health Check Failed and the Deploy Went Live Anyway A postmortem from our own dogfood run: a failed readiness probe still received traffic. What broke, why two correct parts added up to a bug, and the fix.