Skip to content
Latchkey

Anatomy of a CI/CD Pipeline: Build, Test, Deploy

Almost every CI/CD pipeline is some variation on three stages: build, test, and deploy.

A pipeline can look intimidating, but underneath it is a simple, ordered assembly line. This lesson breaks a pipeline into its core stages so you can recognize the structure in any tool, then shows a worked example of code flowing through it.

Stage 1: build

The build stage turns your source code into something runnable: compiling, bundling, installing dependencies, or producing a Docker image. If your code does not even compile or install, there is no point running tests - so build comes first and acts as a fast initial gate. The output of a successful build is often an *artifact*, a packaged result later stages can use.

Stage 2: test

The test stage runs your automated checks against the built code: unit tests, integration tests, linters, type checks, and security scans. This is where most bugs are caught. Tests are usually ordered fast-to-slow so cheap checks fail quickly and give developers feedback in seconds, while slower end-to-end tests run later in the pipeline.

Stage 3: deploy

The deploy stage takes a build that passed all tests and releases it - to a staging environment, then production, or straight to production in continuous deployment. Deploys are often gated: they may require an approval, only run on the main branch, or roll out gradually. A good deploy stage is also reversible, so a bad release can be rolled back quickly.

How a change flows through

Picture a developer pushing a one-line fix. The pipeline checks out the code, installs dependencies and builds (stage 1), runs the test suite (stage 2), and - if everything is green and the change is on the right branch - deploys it (stage 3). If any stage fails, the pipeline stops and reports exactly where, so nothing broken ever reaches production.

.github/workflows/pipeline.yml
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - 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

Key takeaways

  • Most pipelines reduce to three ordered stages: build, test, deploy.
  • Order matters: a failed build short-circuits everything downstream.
  • A change only reaches deploy after passing every earlier gate.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →