Skip to content
Velloreth
Technology 5 min read

CI/CD Explained: Continuous Integration and Delivery

CI merges and tests often, CD ships automatically. Learn the pipeline stages, the difference between delivery and deployment, and the gates.

By

The three terms

Continuous integration (CI) — merge to a shared branch often, and build and test every merge.

Continuous delivery (CD) — keep every commit in a releasable state, and release on demand.

Continuous deployment — release every commit that passes the pipeline, with no human step.

The difference between the last two is one step: delivery stops before production and waits for a decision; deployment does not.

Continuous integration

The problem it solves: a long-lived branch diverges, and the merge at the end is a large, painful conflict.

The practice:

  • Merge to the main branch at least daily
  • Run the build and the tests on every merge
  • Keep the main branch green
  • Fix a broken build immediately

The signal: a build that is red for a day is a build that the team has stopped trusting.

The prerequisite: a test suite that runs in minutes. A suite that takes an hour cannot run on every merge.

The pipeline

A pipeline is a sequence of stages. A failure stops it.

commit
  |
  v
lint  ->  build  ->  unit test  ->  integration test
  |
  v
security scan  ->  deploy staging  ->  smoke test
  |
  v
deploy production  ->  verify

The order matters. The fast checks run first, so a typo is found in seconds rather than after a ten-minute test run.

A stage is a job in most systems, and the jobs can run in parallel when they do not depend on each other.

The stages

Lint — a formatter and a linter. It catches a style problem and a common bug, and it takes seconds.

Build — compile, bundle, produce the artifact. A build failure is the most common early failure.

Unit test — fast, isolated, no network. This is the stage that should be the largest.

Integration test — a real database, a real queue. Slower, and it catches the wiring.

Security scan — a dependency audit and a static analysis. It fails on a critical finding.

Deploy to staging — the same artifact, a production-like environment.

Smoke test — a few requests against the deployed environment.

Deploy to production — the same artifact again.

Verify — a health check and an error-rate watch.

Build once, promote

The rule: build the artifact once, and promote the same artifact through the environments.

Why: the thing that was tested is the thing that is deployed. A rebuild per environment produces a different artifact, and the difference is a source of a bug that only appears in production.

The implementation: a container image tagged with the commit SHA, pushed to a registry, and pulled by each environment.

docker build -t registry/app:${GIT_SHA} .
docker push registry/app:${GIT_SHA}
# staging and production both pull registry/app:${GIT_SHA}

A tag such as latest is not a version. It moves, so it cannot identify what is deployed.

Speed

A fast pipeline is used. A slow one is bypassed.

The techniques:

Cache the dependencies. A lockfile hash as the cache key.

- uses: actions/cache@v4
  with:
    path: ~/.npm
    key: npm-${{ hashFiles('package-lock.json') }}

Parallelise the tests. Split the suite across several runners.

Run the fast tests first. A lint failure should not wait for a ten-minute test run.

Only run what changed. A monorepo can run the tests for the affected packages.

Move the slow tests to a nightly job. An end-to-end suite that takes an hour does not belong on every commit.

The target: under ten minutes for the feedback stage.

Gates

A gate is a check that must pass before a deploy proceeds.

The types:

  • A manual approval for production
  • A passing smoke test
  • A security scan with no critical finding
  • A coverage threshold
  • A change-management ticket

A gate is a deliberate slowdown. It should be reserved for a real risk, and a gate that is always approved is a gate that should be removed.

A manual approval on every deploy is a bottleneck. A manual approval on a production deploy of a critical service is reasonable.

The environment promotion

EnvironmentPurposeData
Developmenta developer’s machinefake
CIthe pipelinefake
Staginga production-like testa copy or fake
Productionthe usersreal

Staging should be as close to production as possible. A difference in the database version or the configuration is a difference that hides a bug.

A preview environment per pull request is a strong practice: it deploys the branch to a temporary URL, so a reviewer can see the change.

Common mistakes

A pipeline that takes an hour. It is bypassed.

Rebuilding per environment. The tested artifact is not the deployed one.

A latest tag. It cannot identify what is deployed.

A red main branch that stays red. The team stops trusting the build.

A test suite with a flaky test. A flaky test trains the team to re-run rather than to investigate.

A secret in the pipeline file. Use the secret store.

No rollback plan. A deploy without a rollback is a deploy with no way back.

A gate that is always approved. It adds a delay and no safety.

No smoke test after the deploy. The problem is found by the users.

A quotable summary

Continuous integration merges to a shared branch often and tests every merge, continuous delivery keeps every commit releasable, and continuous deployment releases every commit that passes the pipeline. A pipeline is a sequence of stages with the fast checks first, and the artifact should be built once and promoted rather than rebuilt per environment. A fast pipeline is used and a slow one is bypassed, and a gate should be reserved for a real risk.

For the pipeline itself, see ci-cd-pipeline-basics and github-actions-basics. For the broader context, blue-green-deployments and docker-basics-guide.

Frequently asked questions

What is the difference between continuous delivery and continuous deployment?
Continuous delivery keeps every commit in a releasable state, and a human decides when to release. Continuous deployment releases every commit that passes the pipeline, with no human step. Delivery is the safer default; deployment requires a strong test suite and a fast rollback.
What is continuous integration?
It is the practice of merging work into a shared branch frequently, and running an automated build and test on every merge. It catches an integration problem early, when the change is small and the cause is obvious, rather than at the end of a long branch.
What stages should a pipeline have?
A typical pipeline has lint, build, unit test, integration test, a security scan, a deploy to staging, a smoke test, and a deploy to production. The order matters: the fast checks run first so a failure is found in seconds rather than minutes.
How long should a CI pipeline take?
Under ten minutes for the feedback stage, and under thirty for the full pipeline. A pipeline that takes an hour is a pipeline that developers work around. The fix is to parallelise the tests, cache the dependencies, and move the slow tests to a later stage.
What is a build artifact?
It is the output of the build, such as a container image or a bundle. The rule is to build it once and promote the same artifact through the environments, so the thing that was tested is the thing that is deployed. Rebuilding per environment means the tested artifact is not the deployed one.
What is a deployment gate?
It is a check that must pass before a deploy proceeds, such as a manual approval, a passing smoke test, or a security scan with no critical findings. A gate is a deliberate slowdown, so it should be reserved for a real risk.