Ankit KanojiyaBeginner

Evergreen guide by Ankit Kanojiya · Beginner · DevOps & Cloud

CI/CD Pipelines Explained: From Commit to Production

A practical walkthrough of how code moves from a commit to production through automated build, test, and deploy stages. Covers the core pipeline anatomy and common trade-offs.

Continuous Integration and Continuous Delivery describe the automation that turns a source change into a running, verified artifact. The goal is to shorten the feedback loop so that defects surface in minutes rather than days, and to make releases a routine, low-drama event.

What CI and CD Actually Mean

Continuous Integration is the practice of merging work into a shared branch frequently and verifying each merge with automated builds and tests. Continuous Delivery extends this: every change that passes the pipeline is kept in a deployable state. Continuous Deployment goes one step further and pushes every passing change to production automatically, with no manual gate.

The distinction matters. Continuous Delivery keeps a human in the loop for the final promotion; Continuous Deployment removes it. Teams usually start with Delivery and graduate to Deployment once test coverage and observability are strong enough to trust.

Anatomy of a Pipeline

A typical pipeline runs as a sequence of stages, each gating the next:

  • Build: compile code, resolve dependencies, produce an artifact.
  • Test: unit, integration, and sometimes end-to-end suites.
  • Package: create an immutable artifact such as a container image.
  • Scan: static analysis, dependency and secret scanning.
  • Deploy: promote to staging, then production.

A key principle is build once, deploy many. The same artifact that passed testing should be the one promoted to production. Rebuilding per environment reintroduces risk, because the bytes you tested are not the bytes you ship.

A Minimal Example

Most hosted CI systems use declarative YAML. The example below builds, tests, and publishes a container image:

name: ci
on:
  push:
    branches: [main]
jobs:
  build-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npm test
      - run: docker build -t registry.example.com/app:${{ github.sha }} .
      - run: docker push registry.example.com/app:${{ github.sha }}

Tagging the image with the commit SHA makes every build traceable to its source and avoids the ambiguity of a mutable tag like latest.

Deployment Strategies

How an artifact reaches production is as important as building it. Common patterns include:

  • Rolling update: replace instances gradually. Simple, but mixes old and new versions during rollout.
  • Blue-green: run two identical environments and switch traffic at once. Fast rollback, but doubles infrastructure during the cutover.
  • Canary: route a small slice of traffic to the new version, watch metrics, then widen. Lowest blast radius, but needs good monitoring.

The right choice depends on tolerance for risk and the cost of idle capacity. Canary deployments pair naturally with automated rollback triggered by error-rate thresholds.

Making Pipelines Fast and Reliable

Slow pipelines get bypassed, so speed is a feature. Practical levers:

# Cache dependencies between runs
npm ci --cache .npm --prefer-offline

# Run independent test suites in parallel
pytest -n auto
  • Cache dependency downloads and build layers.
  • Parallelize independent test suites.
  • Fail fast: run cheap, high-signal checks first.
  • Keep tests deterministic; a flaky suite erodes trust until people ignore red builds.

Trade-offs to Weigh

More automation is not automatically better. A pipeline that gates on a two-hour end-to-end suite will frustrate developers and encourage workarounds. Conversely, deploying automatically without health checks invites outages. Reasonable defaults: keep the critical path under ten minutes, require passing tests before merge, and separate fast feedback (unit tests on every push) from slower verification (nightly integration runs).

Secrets management is another trade-off. Injecting credentials as pipeline variables is convenient but widens the attack surface. Short-lived, scoped tokens from a secrets manager reduce exposure at the cost of extra setup.

Summary

A healthy CI/CD pipeline builds an artifact once, verifies it with fast and trustworthy tests, and promotes it through environments with a deployment strategy matched to risk. Start simple, measure pipeline duration and failure rate, and add gates only where they earn their keep.