CI/CD Pipeline Architecture: Stages, Gates & Deployment Strategies
A well-designed CI/CD pipeline is the difference between deploying with confidence and deploying with dread. This guide covers how to structure pipeline stages, what quality gates to enforce, which deployment strategy fits your reliability requirements, and how GitOps changes the deployment model entirely — with architecture diagrams in code you can adapt immediately.
Related Products
on GumroadDeveloper Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →AI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →You Might Also Need
JSON Formatter & Validator
Format, beautify, and validate JSON online. Paste your JSON to instantly pretty-print it with 2-space, 4-space, or tab indentation. Minify JSON too. Free, runs in your browser.
Open free tool →
Regex Tester
Free regex tester. Test regular expressions against multiple strings with expected match/no-match assertions — see instant pass/fail results. Built-in presets for email, URL, IPv4, and phone. Pro: unl
Open free tool →
Base64 Encoder & Decoder
Free Base64 Encoder & Decoder. Convert text, images, and any file to Base64 and back. Supports URL-safe Base64, image data URIs, and file download from Base64. Runs 100% in your browser — no data sent
Open free tool →
More Free Tools
Related Articles
curl 深度使用手冊:API 測試從入門到進階
curl 是每位開發者必備的 CLI 工具。本文涵蓋 GET/POST/PUT/DELETE 請求、認證、header 設定、檔案上傳、除錯技巧,以及 REST API 測試的完整實戰範例。
Best AI Code Review Tools 2026: CodeRabbit, Sourcery, DeepCode & Bito Compared
Compare top AI code review tools for 2026: CodeRabbit, Sourcery, DeepCode, and Bito. Features, pricing, GitHub/GitLab integration, and choosing the right tool for your team.
AI Code Review Tools 2026: GitHub Copilot, CodeRabbit, Qodo Merge Ranked
Compare AI code review tools for 2026: GitHub Copilot code review, CodeRabbit, Qodo Merge, Sourcery, and PR-Agent. Pricing, accuracy, and GitHub integration.
AI Coding Tools Comparison 2026: GitHub Copilot vs Cursor vs Windsurf vs Cline
Comprehensive comparison of the best AI coding tools in 2026: GitHub Copilot, Cursor, Windsurf, and Cline. Pricing, features, model support, and real-world benchmarks.
AI Pair Programming in 2026: GitHub Copilot vs Cursor vs Claude Code
Master AI pair programming in 2026. Compare GitHub Copilot, Cursor, and Claude Code for autocomplete, chat, and agentic workflows. Includes setup guides and productivity tips.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →Complete 6-Stage Pipeline
A production-grade GitHub Actions pipeline with all six stages: source, build, test, security scan, deploy to staging, and deploy to production with manual approval gate.
name: Production Pipeline
on:
push:
branches: [main]
jobs:
# Stage 1: Source — handled by checkout in each job
# Stage 2 + 3: Build & Test (parallel)
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: actions/upload-artifact@v4
with: { name: dist, path: dist/ }
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm test -- --coverage
- name: Quality Gate — coverage must be ≥80%
run: |
COVERAGE=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage $COVERAGE% is below 80% threshold"; exit 1
fi
# Stage 4: Security
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm audit --audit-level=high
- uses: github/codeql-action/analyze@v3
# Stage 5: Deploy to Staging (auto)
deploy-staging:
needs: [build, test, security]
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/download-artifact@v4
with: { name: dist }
- run: ./scripts/deploy.sh staging
# Stage 6: Deploy to Production (manual approval)
deploy-production:
needs: deploy-staging
runs-on: ubuntu-latest
environment:
name: production
url: https://example.com
steps:
- uses: actions/download-artifact@v4
with: { name: dist }
- run: ./scripts/deploy.sh production Deployment Strategies Compared
The right deployment strategy depends on your tolerance for downtime, infrastructure budget, and traffic volume. Here is a concise comparison of the three main approaches.
# Blue-Green: two environments, instant traffic switch
# Infrastructure: 2x cost
# Rollback time: seconds (flip load balancer)
resource "aws_lb_listener_rule" "blue_green_switch" {
action {
type = "forward"
target_group_arn = var.active_env == "blue" ? aws_lb_target_group.blue.arn : aws_lb_target_group.green.arn
}
}
# Canary: route % of traffic to new version
# Tools: AWS CodeDeploy, Argo Rollouts, Istio, nginx split_clients
# Monitor for 15min at 5%, then ramp to 50%, then 100%
# Rolling: replace instances gradually
# Kubernetes rolling update (default strategy)
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # add 1 new pod before removing old
maxUnavailable: 0 # never reduce below desired count GitOps with ArgoCD
In a GitOps pipeline, CI handles build and image push. Deployment is driven by a separate manifest repository watched by ArgoCD — any change to the manifests is automatically applied to the cluster.
# CI pipeline: build image and update manifest repo
- name: Build and push image
run: |
docker build -t myorg/app:$GITHUB_SHA .
docker push myorg/app:$GITHUB_SHA
- name: Update manifest repository
run: |
git clone https://x-token:${{ secrets.MANIFEST_TOKEN }}@github.com/myorg/k8s-manifests.git
cd k8s-manifests
# Update image tag in Helm values
yq e '.image.tag = "${{ github.sha }}"' -i apps/myapp/values.yaml
git commit -am "chore: update myapp to ${{ github.sha }}"
git push
# ArgoCD Application manifest (in k8s-manifests repo)
# argocd-app.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: myapp
spec:
source:
repoURL: https://github.com/myorg/k8s-manifests
path: apps/myapp
targetRevision: main
destination:
server: https://kubernetes.default.svc
namespace: production
syncPolicy:
automated:
prune: true
selfHeal: true Deployment Strategy Decision Matrix
| Strategy | Downtime | Rollback speed | Infra cost | Best for |
|---|---|---|---|---|
| Blue-Green | Zero | Seconds | 2x | Critical services, regulated environments |
| Canary | Zero | Minutes | ~1.1x | High-traffic, risk-sensitive releases |
| Rolling | Zero (if configured) | Minutes | ~1x | Most Kubernetes workloads (default) |
| Recreate | Brief downtime | Minutes | 1x | Dev/staging, non-critical services |
Frequently Asked Questions
What are the essential stages in a CI/CD pipeline?▼
A complete CI/CD pipeline typically has six stages: (1) Source — code checkout, branch policies. (2) Build — compile, bundle, create artifacts. (3) Test — unit tests, integration tests, code coverage. (4) Security — SAST, dependency scanning, secret detection. (5) Deploy — push artifact to environment (staging, production). (6) Monitor — health checks, rollback triggers, observability. Not every pipeline needs all six; a small internal tool might skip security scanning. Start with Source→Test→Deploy and add stages as the project matures.
What is a quality gate and what should mine check?▼
A quality gate is a pass/fail checkpoint that blocks pipeline progression if minimum standards are not met. Typical gates: test coverage must be ≥80%, no HIGH or CRITICAL severity vulnerabilities, lint must pass with zero errors, build size must not exceed threshold. In SonarQube, quality gates are configured per project. In GitHub Actions, a status check on the branch protection rule acts as a quality gate — PRs cannot merge unless it passes.
Blue-green vs canary vs rolling deployment — when to use each?▼
Blue-green: run two identical production environments, switch traffic instantly by flipping DNS or load balancer. Zero-downtime, instant rollback. Costs double the infrastructure. Best for: critical services where any downtime is unacceptable. Canary: route a small % of traffic (1-5%) to the new version, monitor error rates and latency, gradually increase to 100% if metrics are healthy. Best for: high-traffic services where you want real production signal before full rollout. Rolling: gradually replace old instances with new ones, a few at a time. Lower cost than blue-green, slower rollback. Best for: services with multiple instances where infrastructure cost is a concern.
What is GitOps and how does it relate to CI/CD pipelines?▼
GitOps is a deployment pattern where the desired state of your infrastructure and applications is stored in Git, and automated agents continuously reconcile the live environment to match. In a GitOps model, your CI pipeline builds and pushes a container image, then updates a manifest repository (Helm chart or Kubernetes YAML) with the new image tag. A GitOps agent (ArgoCD, Flux) watches the manifest repository and applies changes to the cluster automatically. The key benefit: Git becomes your audit trail — every change is a commit, and rollback is a git revert.
Trunk-based development vs GitFlow — which branching strategy is better for CI/CD?▼
Trunk-based development (TBD) is better for CI/CD velocity. All developers commit to a single main branch (or short-lived feature branches that merge within hours). This keeps the pipeline simple: main is always deployable, CI runs on every commit, and there are no long-lived branches to merge and conflict. GitFlow uses long-lived develop, release, and hotfix branches. It was designed for scheduled release cycles and adds significant merge complexity. Unless you maintain multiple versions in production simultaneously, trunk-based development with feature flags is the modern best practice.
What is pipeline-as-code and why does it matter?▼
Pipeline-as-code means your CI/CD configuration lives in version-controlled files (Jenkinsfile, .github/workflows/, .gitlab-ci.yml) alongside application code. This means pipeline changes go through the same review process as code changes — PRs, code review, and rollback via git. It also enables testing pipeline changes in feature branches before merging. The alternative — configuring pipelines through UI click-ops — is fragile, unauditable, and impossible to reproduce. Pipeline-as-code is a non-negotiable best practice for any team beyond one person.