CI/CD Fundamentals and Pipeline Design

Tool-agnostic CI/CD: continuous integration vs delivery vs deployment, the stages of a good pipeline, artifacts and promotion, branching strategies, deployment strategies, pipeline security, DORA metrics, and how to choose between Jenkins, GitHub Actions, GitLab CI and Argo CD.

Intermediate⏱ 9 min readLesson 14 of 17#ci-cd#pipeline#devops#jenkins#github-actions#deployment

The big idea

Lesson 9 showed CI/CD with one tool (GitHub Actions). This lesson steps back and explains the ideas that every CI/CD tool shares. Once you understand them, Jenkins, GitLab CI, GitHub Actions and Azure Pipelines are just different syntax for the same thing.

Think of a pipeline as a factory assembly line for code. A change goes in at one end. At each station a machine checks or builds something. If any station finds a defect, the line stops. What comes out at the end is a tested, packaged product that is safe to ship.

A pipeline moves a commit through build, test, package, and deploy stages, with quality gates between them and a single artifact promoted from staging to production

CI, continuous delivery, continuous deployment

These three terms are often mixed up:

TermWhat is automatedWho presses "release"?
Continuous Integration (CI)Every push is built and tested; everyone merges to main often (at least daily)Nobody: nothing is released yet
Continuous DeliveryEvery passing change is packaged and deployed to staging, ready for productionA person approves the production deploy
Continuous DeploymentEvery passing change goes all the way to productionNobody: the pipeline does it

💡 Most teams start with CI, add continuous delivery, and only move to continuous deployment once they have good tests, monitoring and fast rollbacks.

The stages of a good pipeline

StageTypical commandsGoalUsual time
1. Checkoutgit cloneGet the exact commitSeconds
2. Installnpm ci, pip install -r, mvn dependency:go-offlineReproducible dependencies from a lock fileUnder 1 min with cache
3. Static checksLint, format check, type checkCatch cheap mistakes firstSeconds
4. Unit testsnpm test, pytest, go test ./...Logic is correct1 to 3 min
5. Build / packagenpm run build, docker build, mvn packageProduce one artifact1 to 5 min
6. Security scansnpm audit, Trivy, Semgrep, secret scanningNo known vulnerable deps or leaked keys1 to 2 min
7. Integration / E2E testsPlaywright, TestcontainersPieces work together3 to 15 min
8. Publish artifactPush image to a registry, upload a .tgzStore the tested buildSeconds
9. Deploy to stagingHelm, SSH + script, kubectl applyReal environment check1 to 3 min
10. Approval / smoke testManual approve, health checkLast safety gateVaries
11. Deploy to productionSame script, different targetRelease1 to 3 min
12. VerifyHealth checks, error rate, metricsRoll back automatically if badMinutes

Order matters: run the fastest, cheapest checks first. A lint error should fail the build in 20 seconds, not after a 10-minute E2E run.

Keep the pipeline fast

A pipeline that takes 45 minutes gets skipped, batched, or ignored. Aim for under 10 minutes to a green CI result.

  • Cache dependencies (~/.npm, ~/.m2, Docker layers).
  • Run independent jobs in parallel (lint, unit tests and build at the same time).
  • Split slow test suites across several machines.
  • Only run expensive jobs when needed (for example, E2E only on main or on PRs that touch the frontend).

Build once, promote the same artifact

The most important rule in CD:

Build the artifact once. Deploy that exact artifact to every environment.

❌ Rebuild per environment✅ Build once, promote
Staging and production each run npm run buildCI builds myapp:3f9c2a1 once
Different dependency versions can sneak inStaging gets myapp:3f9c2a1
"It worked in staging" means littleProduction gets the same myapp:3f9c2a1

Tag artifacts with the commit SHA (and optionally a semantic version like v1.4.2). Never deploy latest to production: you can't tell what's running or roll back to it.

Configuration that differs per environment (database URL, API keys) comes from environment variables or secrets at deploy time, not from the build.

Branching strategies

StrategyHow it worksGood for
Trunk-basedShort-lived branches (hours to a day or two), merge to main often, hide unfinished work behind feature flagsMost teams doing CI/CD; fastest feedback
GitHub FlowBranch → PR → review + CI → merge to main → deployWeb apps and SaaS
GitFlowdevelop, release/*, hotfix/*, main branchesVersioned products with planned releases (mobile apps, desktop software)

Long-lived branches are the enemy of CI: the longer a branch lives, the bigger and riskier the merge. If your team does "merge week", you are not doing continuous integration.

Deployment strategies

StrategyHowRollbackCost
RecreateStop old, start newRedeploy old versionDowntime
RollingReplace servers or pods a few at a timeRoll forward or back graduallyLow
Blue/greenRun new version beside old, switch traffic at onceSwitch back instantlyDouble capacity briefly
CanarySend 1% → 10% → 50% → 100% of traffic to new version while watching metricsStop and send traffic backNeeds good metrics
Feature flagsCode is deployed but switched off; turn it on per user or percentageFlip the flag offFlag management

Lesson 11 shows blue/green and symlink releases on a single server in detail.

Environments

Drawing diagram…
  • Staging should look like production: same OS, same versions, same deploy script, smaller size.
  • Each environment has its own secrets. A staging job must never be able to read production credentials.
  • Use infrastructure as code (the Terraform section) so environments don't drift apart.

Pipeline security

A CI server can deploy to production, so it is a juicy target. Treat it like production.

RiskDefense
Secrets leaked in logsUse the tool's secret store; never echo a secret; mask output
A malicious PR runs code on your CIDon't give secrets to PRs from forks; require approval for first-time contributors
Compromised third-party plugin or actionPin versions (or commit SHAs); install only what you need; update regularly
CI has admin access everywhereLeast privilege: a deploy key that can only deploy one app
Long-lived cloud keysUse short-lived credentials (OIDC federation to AWS/GCP/Azure)
Vulnerable dependencies shippedDependency and image scanning as a pipeline stage
Tampered artifactsSign images (cosign) and verify before deploy

Measure it: the DORA metrics

The DORA research program found four numbers that separate high-performing teams from the rest:

MetricQuestionElite teams
Deployment frequencyHow often do we deploy to production?On demand, many times a day
Lead time for changesCommit → running in productionLess than a day
Change failure rateWhat share of deploys cause an incident?Low (around 5% or less)
Time to restore serviceHow fast do we recover from a failure?Less than an hour

Speed and stability are not a trade-off: small, frequent, automated deploys are both faster and safer.

Choosing a CI/CD tool

ToolHostingPipeline fileStrengthsWatch out for
JenkinsSelf-hostedJenkinsfile (Groovy)Free, runs anywhere (including air-gapped networks), 1,800+ plugins, very flexibleYou maintain the server, upgrades, plugins and security
GitHub ActionsHosted or self-hosted runners.github/workflows/*.ymlBuilt into GitHub, huge marketplace, zero setupTied to GitHub; minutes cost money on private repos
GitLab CIHosted or self-hosted.gitlab-ci.ymlAll-in-one with GitLab (registry, environments, security)Best when your code is on GitLab
Azure PipelinesHostedazure-pipelines.ymlGood for Microsoft/.NET shopsAzure DevOps ecosystem
CircleCI, BuildkiteHosted (Buildkite: your own agents)YAMLFast, good parallelismPaid at scale
Argo CD, FluxIn your Kubernetes clusterGit repo of manifestsGitOps: the cluster pulls desired state from GitCD only; pair with a CI tool

Rule of thumb:

  • Code on GitHub, cloud servers, small team → GitHub Actions.
  • Code on GitLab → GitLab CI.
  • Many repos, on-premises servers, strict network rules, or a company that already runs it → Jenkins (lessons 15 and 16).
  • Kubernetes deployments → CI tool builds the image, Argo CD deploys it.

Key takeaways

  • CI = build and test every change; continuous delivery = always ready to release with an approval; continuous deployment = release automatically.
  • Order stages from fast and cheap to slow and expensive; keep CI under about 10 minutes.
  • Build once, promote the same artifact, tagged with the commit SHA.
  • Short-lived branches and feature flags make CI work.
  • Secure the pipeline like production and track the four DORA metrics.

Try it yourself

Draw your current release process as boxes on paper, from git push to "users see it". Mark every manual step with a ✋. Pick the one that breaks most often and automate it first.