A reliable CI/CD pipeline turns a code change into a tested, traceable, and reversible release. This guide provides a reusable workflow and practical checklist for designing the stages from commit through production, including dependency caching, parallel tests, artifact promotion, approvals, secrets, deployment strategies, rollback triggers, and failure notifications.
Overview
A CI/CD pipeline should make the safe path the easiest path. Every change should be checked consistently, built once, promoted through controlled environments, and deployed with enough evidence to support a fast decision. The exact implementation may use a hosted CI service, self-managed runners, GitOps controllers, or deployment APIs, but the design principles remain broadly applicable.
A useful pipeline separates validation from release. Pull request jobs answer whether the proposed change is suitable for merging. Post-merge jobs create a versioned artifact and verify it in an environment. Release jobs promote that same artifact rather than rebuilding it for each destination. This prevents a test environment and production from receiving subtly different outputs.
A practical default workflow is:
- Trigger on a pull request, merge, or explicitly approved release action.
- Check out the source at a known revision and establish the required toolchain.
- Restore dependency and build caches using keys that include the lockfile or equivalent dependency definition.
- Run fast formatting, linting, type, unit, and security checks in parallel where their inputs are independent.
- Build an immutable artifact, such as a container image or package, and record its source revision.
- Publish test results, logs, a software bill of materials where appropriate, and provenance or signing metadata supported by the toolchain.
- Deploy the artifact to a lower environment, run integration and smoke tests, then promote it with explicit controls.
- Monitor the release, notify the responsible team, and roll back or halt promotion when defined thresholds are breached.
For containerized services, pair this workflow with a Kubernetes deployment readiness checklist. For broader supply-chain controls, review the software supply chain security guide.
Checklist by scenario
For pull request validation
- Run checks against the proposed revision, not an untracked local state.
- Fail quickly on formatting, lint, type, and configuration errors before expensive jobs begin.
- Cache dependencies and build outputs carefully. Include the operating system, runtime version, lockfile hash, and relevant build configuration in the cache key.
- Run independent unit, API, and static analysis jobs in parallel. Keep required checks visible and consistently named.
- Prevent secrets from being exposed to untrusted pull request code. Treat forked or external contributions as a separate trust boundary.
- Upload useful failure artifacts, such as test reports, coverage output, and application logs, without publishing credentials or personal data.
For the build and release candidate
- Build once after merge and assign a unique version, commit identifier, or digest.
- Pin base images, actions, plugins, and critical tooling according to your maintenance policy.
- Scan dependencies, source, images, and infrastructure definitions at the stage where findings can still be fixed cheaply.
- Generate an SBOM or equivalent component record when it fits the service's risk and compliance requirements.
- Store artifacts in a registry with access controls and retention rules. Do not rely on a runner's local filesystem as the release store.
- Record who or what initiated the build, which source revision was used, and which checks passed.
For staging or pre-production deployment
- Deploy the exact artifact that will be promoted to production.
- Use environment-specific configuration separately from the artifact, with validation for required values.
- Run database migration checks, integration tests, smoke tests, and representative health checks.
- Confirm observability is ready: logs, metrics, traces, dashboards, and alerts should identify the new version.
- Use an approval only where a human decision adds value, such as a high-risk production change. Keep routine, low-risk delivery automated.
For production deployment and rollback
- Choose a strategy that matches the service: rolling, blue-green, canary, or a controlled replacement.
- Define rollout conditions before deployment, including readiness, error rate, latency, saturation, and business checks where relevant.
- Make rollback a tested operation, not merely a button in the pipeline. Retain the previous known-good artifact and configuration.
- Decide how database schema changes remain compatible during both forward deployment and rollback.
- Notify the owning team when a deployment starts, completes, pauses, fails, or rolls back. Link notifications to logs, dashboards, and the pipeline run.
- Record the final status and deployment metadata for incident review and release auditing.
What to double-check
Trust boundaries: Review which jobs can access cloud credentials, package registries, signing keys, and production environments. Use short-lived credentials or workload identity where supported, restrict permissions, and keep production secrets out of logs. A deployment pipeline should request only the access required for its current stage. See the Kubernetes secrets management guide for related operational considerations.
Artifact identity: Verify that promotion references a digest or immutable version rather than a mutable tag such as latest. If a deployment manifest is changed after testing, treat it as a new change and repeat the appropriate checks.
Failure behavior: Test what happens when a runner disappears, a cache is corrupt, an integration test times out, an artifact registry is unavailable, or a deployment becomes partially healthy. Jobs should fail clearly, clean up temporary resources, and preserve enough evidence for diagnosis.
Operational readiness: A green pipeline does not prove that a service is reliable in production. Connect deployment checks to service-level objectives, error budgets, and an owner who can respond. The SLO and error budget workflow can help turn release signals into an operational decision.
Infrastructure changes: Separate application and infrastructure paths when their risk, reviewers, or rollback methods differ. Run plan, policy, and validation checks before applying infrastructure changes; the Terraform module testing workflow offers a useful model for this boundary.
Common mistakes
- Rebuilding at every environment: Different builds can contain different dependencies or generated output. Build once, then promote.
- Making every check sequential: This increases feedback time without improving safety when jobs are independent. Parallelize carefully and preserve clear required-status rules.
- Using caches as a source of truth: Caches are an optimization. A clean runner should still be able to build from declared dependencies.
- Putting secrets in repository variables without a threat model: Scope credentials by environment and job, mask output, rotate them, and check that debugging options cannot print them.
- Relying on manual rollback alone: Write down the trigger, owner, command or workflow, data considerations, and verification steps. Practice it during a low-risk change.
- Ignoring migrations and asynchronous work: A code rollback may not reverse a schema change, queued message, or external side effect. Use backward-compatible changes and explicit recovery procedures.
- Alerting on pipeline events without ownership: Notifications should identify the service, revision, environment, failure stage, and next action. Route them to a maintained team channel or incident path.
When to revisit
Review the pipeline before seasonal planning cycles, service launches, major architecture changes, and changes to deployment ownership. Revisit it whenever the CI provider, runner image, runtime, package manager, registry, deployment API, or security tooling changes. A platform update can alter permissions, supported actions, cache behavior, or authentication assumptions even when the application code is unchanged.
At least twice a year, walk through the checklist with developers, operators, and security stakeholders. Remove obsolete stages, confirm that required checks still test meaningful failure modes, inspect runner and credential permissions, and verify that rollback artifacts remain available. After a failed release or incident, update the pipeline and runbook with the observed failure rather than relying on informal memory.
For a practical next step, choose one service and document its pipeline using these headings: trigger, checks, artifact, environments, approvals, secrets, deployment strategy, health signals, rollback trigger, owner, and notification path. Run one controlled release, simulate a rollback, and fix every unclear step. That exercise will expose more design gaps than adding another generic job to the workflow.