Skip to main content

Understanding CI/CD Pipelines and Delivery Stages

Learn what CI/CD means, how pipelines split into stages and jobs, and how fail-fast ordering and fast feedback cut release risk at scale.

22 Terms

Overview and What You Will Learn

CI/CD is the practice of automatically building, testing, and delivering every code change through a pipeline, so releases become routine instead of risky events. Continuous Integration (CI) merges and verifies changes often, Continuous Delivery keeps every verified change ready to release, and Continuous Deployment releases it to production automatically with no manual approval.

A pipeline is the automated path a commit follows. It is made of stages and jobs, started by a trigger, and it produces artifacts such as a container image. Ordering the cheapest checks first, called fail-fast, is what keeps feedback quick.

By the end of this topic you will be able to:

  • Explain the difference between CI, Continuous Delivery, and Continuous Deployment
  • Read a GitHub Actions workflow and identify its triggers, jobs, dependencies, and artifacts
  • Order pipeline stages using the fail-fast principle
  • Build a container image once and promote the same image to every environment
  • Diagnose a failing run and measure pipeline speed and reliability

Why This Matters in Production

Pipeline speed decides how engineers work. When feedback takes 45 minutes, people switch tasks, forget the context, and batch up changes, which makes each release bigger and riskier. When feedback takes about 10 minutes, engineers fix problems while the change is still fresh and ship small changes often.

Small, frequent releases are easier to review, easier to test, and easier to roll back. Teams that ship many times a day, such as those at Shopify, Spotify, or Razorpay, depend on automated pipelines to make that safe. Slow or flaky pipelines push teams back toward big, infrequent, high-risk releases.

Core Principles

The three terms describe how far automation goes. Each stage adds trust in the change before it reaches users.

flowchart TD A(["Commit pushed"]):::slate subgraph CI["Continuous Integration"] B["Build and lint"]:::blue C["Test and scan"]:::blue end subgraph CD["Continuous Delivery"] D[("Versioned artifact")]:::purple E["Deploy to staging"]:::green end F{"Approval gate"}:::orange G(["Production"]):::slate A --> B --> C --> D --> E --> F --> G classDef slate fill:#475569,color:#ffffff classDef blue fill:#326CE5,color:#ffffff classDef purple fill:#8B5CF6,color:#ffffff classDef green fill:#10B981,color:#ffffff classDef orange fill:#F97316,color:#ffffff

Continuous Deployment is the same flow with the approval gate removed. It needs strong test coverage, fast rollback, and feature flags before it is safe.

How a Pipeline Is Built

A pipeline has five parts:

  1. Trigger: the event that starts it, such as a push, a pull request, a schedule, or a manual dispatch.
  2. Stage: a phase such as test or deploy. In GitHub Actions the same idea is expressed through job dependencies.
  3. Job: a unit of work that runs on its own runner. Jobs without dependencies run in parallel.
  4. Step: one command or action inside a job.
  5. Artifact: a file or image a job produces for later jobs or for release.
The Fail-Fast Principle

Run the cheapest, fastest checks first so a broken change is rejected in seconds, not after a long build. Run independent checks in parallel.

  1. Lint and format (about 10 seconds): catches typos and style errors.
  2. Unit tests (about 2 minutes): catches logic errors.
  3. Build the container image (about 3 minutes): only worth doing once tests pass.
  4. Integration tests and security scan (about 5 minutes, in parallel): need a built artifact.
  5. Deploy to staging (about 2 minutes): runs only after every gate passes.
Remember

Build the artifact once and promote that exact image, by digest or commit SHA, through staging and production. Rebuilding per environment means production runs something that was never tested.

Detailed Step-by-Step Practical Lab

Step 1 - Read a Complete Pipeline Definition

This workflow follows fail-fast ordering. Lint and unit tests run in parallel, the image is built and pushed only after both pass and only on main, and staging deploys last.

flowchart TD T(["Push or pull request"]):::slate L["lint"]:::blue U["unit-test"]:::blue B["build-push"]:::orange D["deploy-staging"]:::green T --> L T --> U L --> B U --> B B -->|"main only"| D classDef slate fill:#475569,color:#ffffff classDef blue fill:#326CE5,color:#ffffff classDef orange fill:#F97316,color:#ffffff classDef green fill:#10B981,color:#ffffff
YAML
name: Payment API CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
# Default to read-only; jobs ask for more only when they need it
permissions:
contents: read
# New pushes cancel older PR runs, but never cancel a run on main
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
ECR_REGISTRY: 123456789012.dkr.ecr.ap-south-1.amazonaws.com
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm # reuse the npm cache between runs
- run: npm ci && npm run lint
unit-test: # no needs: runs in parallel with lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci && npm test
build-push:
needs: [lint, unit-test] # both must pass first
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # lets the job request an OIDC token
outputs:
image-tag: ${{ steps.meta.outputs.tag }}
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-payment-api-build-role
aws-region: ap-south-1
- uses: aws-actions/amazon-ecr-login@v2
- id: meta
run: echo "tag=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
- run: |
docker build -t "$ECR_REGISTRY/payment-api:${GITHUB_SHA}" .
docker push "$ECR_REGISTRY/payment-api:${GITHUB_SHA}"
deploy-staging:
needs: build-push # must list build-push to read its outputs
runs-on: ubuntu-latest
environment: staging
permissions:
contents: read
id-token: write
env:
IMAGE_TAG: ${{ needs.build-push.outputs.image-tag }}
steps:
- uses: actions/checkout@v4
- run: ./deploy.sh staging "$IMAGE_TAG"
Common Mistake

Reading needs.build.outputs.* from a job that does not list build in its own needs. The needs context only contains the jobs you directly depend on, so the value comes back empty.

Step 2 - Trace a Commit Through the Pipeline

Here is what happens from git push to staging, with realistic timings.

Bash
git add payments/processor.js
git commit -m "fix: handle timeout in payment processor"
git push origin main
Bash
1. GitHub receives the push and starts the workflow within seconds
2. lint (23s) and unit-test (2m 14s, 847 tests) run in parallel on two runners
3. build-push starts only after both pass: builds and pushes payment-api:abc1234
4. deploy-staging runs helm upgrade with image.tag=abc1234 and checks pod health
5. A Slack notification reports the result
Total: about 8 minutes from push to staging
Step 3 - Control When the Pipeline Runs With Triggers

Triggers decide which events start a workflow. Path filters keep documentation-only changes from running a full build.

YAML
on:
push:
branches: [main]
paths-ignore: # skip runs for docs-only changes
- '**.md'
- 'docs/**'
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
schedule:
- cron: '0 21 * * *' # cron is UTC: 21:00 UTC is 02:30 IST
workflow_dispatch: # manual run from the Actions tab or gh CLI
inputs:
environment:
type: choice
options: [staging, production]
required: true
Tip

Use either paths or paths-ignore on one event, not both. If a required status check is skipped by a path filter, the pull request can get stuck waiting for it, so test the combination with branch protection before relying on it.

Step 4 - Pass Artifacts Between Jobs

Jobs run on separate machines, so files must be uploaded as artifacts to be reused. This lets tests run against the exact build output.

YAML
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: actions/upload-artifact@v4
with:
name: dist-files
path: dist/
retention-days: 7
test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: dist-files
path: dist/
- run: npm test
- uses: actions/upload-artifact@v4
if: always() # keep the report even when tests fail
with:
name: test-results
path: test-results/junit.xml
Step 5 - Diagnose a Failing Pipeline

Work from the run list down to the failing step, then reproduce locally. The gh CLI shows each level.

Bash
# 1. Find the failed run
gh run list --workflow=ci.yaml --limit 5
# 2. See which job and step failed
gh run view 9876543
# 3. Print only the logs of failed steps
gh run view 9876543 --log-failed
# 4. Reproduce locally with just the failing test
npm test -- src/payments/processor.test.js
# 5. Fix, push, and re-run only the failed jobs if the cause was transient
git commit -am "fix: mock timer in processor timeout test"
git push
gh run rerun 9876543 --failed
Step 6 - Measure Pipeline Health

Track speed and reliability, since a pipeline that is slow or often red gets ignored. These commands use the GitHub CLI and jq.

Bash
# Pass and fail counts over the last 50 runs
gh run list --workflow=ci.yaml --limit 50 --json conclusion \
| jq 'group_by(.conclusion) | map({result: .[0].conclusion, count: length})'
# Duration of each job in one run, in seconds
gh run view 9876543 --json jobs \
| jq '.jobs[] | {name: .name, seconds: ((.completedAt|fromdate) - (.startedAt|fromdate))}'

A test that passes on re-run with no code change is flaky. Track how often runs need a re-run, and quarantine or fix those tests.

Production Best Practices & Common Pitfalls

Mistake Problem Fix
One giant job with 20 steps No parallelism, slow feedback Split into jobs with needs
Slow checks before fast ones Typos cost minutes to find Order by cost, cheapest first
Rebuilding the image per environment Production runs an untested build Build once, promote the same image
No retention-days on artifacts Storage fills up Set retention on every artifact
Ignoring flaky tests Failures stop meaning anything Quarantine, fix, or delete them
Broad default token permissions A compromised step can write to the repo Set top-level permissions: contents: read
  • Set time budgets per stage. For example build under 5 minutes, tests under 8, deploy under 3. Treat a breach as a bug to fix.
  • Cache dependencies. Caching node_modules or the package manager cache often saves minutes on every run.
  • Keep pipelines as code. Workflow files live in the repo, so changes to the pipeline are reviewed like any other change.
  • Gate production. Use GitHub Environments with required reviewers for the approval step in Continuous Delivery.
Common Mistake

Treating a slow green pipeline as healthy. A pipeline that passes after 45 minutes still fails its purpose, which is fast feedback.

Remember

The pipeline verifies good code, it does not replace code review. If reviewers lean on the pipeline to catch every edge case, the test suite grows slow and flaky.

Security

Never print secrets or run env in pipeline logs. Masking only matches exact strings, so derived or encoded values can leak. Register derived values with ::add-mask::.

Quick Reference & Troubleshooting Commands

Task Command
List recent runs gh run list --workflow=ci.yaml
View run details gh run view RUN_ID
View failed logs only gh run view RUN_ID --log-failed
Re-run failed jobs gh run rerun RUN_ID --failed
Cancel a run gh run cancel RUN_ID
Trigger manually gh workflow run ci.yaml
Watch a run live gh run watch RUN_ID
Symptom Likely Cause Fix
Job output is empty Job missing from needs Add the producing job to needs
Deploy job never starts An earlier job failed or was skipped Check needs and if conditions
Runs on README edits No path filter Add paths-ignore
Artifact name conflict Two jobs upload the same name Use unique artifact names per run
Required check stays pending Path filter skipped the workflow Adjust filters or branch protection

Resources

Explore More in CI/CD Fundamentals and Pipeline Design

All 3 Topics

Frequently Asked Questions

Is Understanding CI/CD Pipelines and Delivery Stages free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Understanding CI/CD Pipelines and Delivery Stages topic cover?

Learn what CI/CD means, how pipelines split into stages and jobs, and how fail-fast ordering and fast feedback cut release risk at scale.

Found a mistake, an outdated step or a broken link?