How do you implement CI/CD pipelines for automated software delivery?
CI/CD automates the path from code change to production deployment. CI (Continuous Integration): automatically build and test code on every commit. CD (Continuous Delivery): automatically deploy tested code to staging; Continuous Deployment extends this to production. Pipeline stages: (1) Source: trigger on code push (Git webhook), (2) Build: compile code, install dependencies, create artifacts, (3) Unit test: run fast tests in isolation, (4) Static analysis: linting, type checking, security scanning, (5) Integration test: test with real dependencies, (6) Build artifact: create Docker image or deployment package, (7) Deploy to staging: automated deployment, (8) E2E test: run browser tests against staging, (9) Deploy to production: with approval gate for CD or automatic for continuous deployment. Implementation: GitHub Actions (YAML workflows, tight GitHub integration), GitLab CI (built into GitLab, strong Docker support), CircleCI (fast, good parallelism), and Jenkins (self-hosted, maximum flexibility). Best practices: keep CI fast (under 10 minutes for unit tests), parallelize test execution, cache dependencies between runs, use multi-stage Docker builds for efficient images, implement branch protection requiring CI pass before merge, and implement trunk-based development (short-lived branches, frequent integration). Security in CI/CD: scan dependencies for vulnerabilities (Snyk, Dependabot), scan container images (Trivy), implement SAST (SonarQube, Semgrep), secure secrets using CI platform secret management (never in code), and implement signed commits and artifacts. Metrics: deployment frequency, lead time for changes (commit to production), change failure rate, and mean time to recovery. These are the DORA metrics that correlate with high-performing engineering teams.