Skip to main content

CI/CD Practices

Continuous integration and continuous delivery (CI/CD) practices define how code changes flow from developer commit through automated verification to production deployment. This reference specifies pipeline stage requirements, environment promotion rules, deployment strategy configurations, and tooling standards for mission-driven organisations operating across diverse infrastructure contexts.

Continuous Integration (CI)
The practice of merging code changes to a shared repository frequently, with each merge triggering automated build and test processes that verify the change does not break existing functionality.
Continuous Delivery (CD)
The practice of maintaining code in a deployable state at all times, with automated processes capable of releasing any successful build to production through a single manual approval.
Continuous Deployment
An extension of continuous delivery where every change passing automated verification deploys to production without manual intervention.
Pipeline
An automated sequence of stages that transforms source code into deployed software, with each stage performing specific verification or transformation tasks.
Artifact
A versioned, immutable output produced by a build process, such as a container image, compiled binary, or deployment package.

Pipeline architecture

A CI/CD pipeline consists of sequential stages, each with defined inputs, outputs, and success criteria. Every stage must complete successfully before the next stage begins. Failed stages halt the pipeline and notify responsible parties.

+------------------------------------------------------------------+
| CI/CD PIPELINE FLOW |
+------------------------------------------------------------------+
| |
| +----------+ +----------+ +----------+ +----------+ |
| | | | | | | | | |
| | SOURCE +--->+ BUILD +--->+ TEST +--->+ SECURITY | |
| | | | | | | | | |
| +----------+ +----------+ +----------+ +----------+ |
| | | | | |
| v v v v |
| Checkout Compile Unit tests SAST scan |
| Validate Package Integration Dependency |
| Lint Version Contract Secret detect |
| Tag |
| |
| +----------+ +----------+ +----------+ +----------+ |
| | | | | | | | | |
| | ARTIFACT +--->+ DEPLOY +--->+ VERIFY +--->+ PROMOTE | |
| | | | DEV | | | | | |
| +----------+ +----------+ +----------+ +----------+ |
| | | | | |
| v v v v |
| Store image Deploy to Smoke tests Gate check |
| Sign development Health check Approval |
| Scan Configure E2E subset Next env |
| |
+------------------------------------------------------------------+

Figure 1: Pipeline stage sequence from source commit through environment promotion

Stage requirements

Each pipeline stage has mandatory elements that must be present for the pipeline to meet organisational standards.

Source stage

The source stage retrieves code and validates basic integrity before resource-intensive operations begin.

RequirementSpecificationFailure action
Repository checkoutFull clone for release branches, shallow clone (depth 50) for feature branchesAbort pipeline
Commit signatureGPG signature verification for protected branchesAbort pipeline
Branch policyMerge commits only from approved base branchesAbort pipeline
Lint executionLanguage-appropriate linter with zero tolerance for errorsAbort pipeline
Format verificationCode formatting matches project standardAbort pipeline
Commit messageFollows conventional commit formatWarning only

Source stage timeout: 5 minutes maximum. Stages exceeding this threshold indicate network or repository issues requiring investigation.

Build stage

The build stage compiles source code, resolves dependencies, and produces versioned artifacts.

RequirementSpecificationFailure action
Dependency resolutionLock file verification, no floating versions in production buildsAbort pipeline
CompilationZero warnings policy for production buildsAbort pipeline
Version taggingSemantic version derived from git tags or commit metadataAbort pipeline
Build reproducibilitySame inputs produce byte-identical outputsWarning, investigate
Cache utilisationDependency and build caches reduce rebuild time by minimum 60%Warning only
Build metadataEmbed commit SHA, build timestamp, builder version in artifactAbort pipeline

Build stage timeout varies by project complexity:

Project typeMaximum build timeCache expectation
Frontend application10 minutes70% cache hit rate
Backend service15 minutes65% cache hit rate
Mobile application25 minutes50% cache hit rate
Monorepo (affected only)20 minutes80% cache hit rate

Test stage

The test stage executes automated verification at multiple levels. Test stage composition reflects the project’s Testing Strategy but must include minimum coverage.

Test typeMinimum requirementMaximum durationFailure threshold
Unit tests80% line coverage for new code5 minutes0 failures
Integration testsAll external service boundaries10 minutes0 failures
Contract testsAll API consumer contracts5 minutes0 failures
Smoke testsCritical path verification3 minutes0 failures

Test parallelisation is mandatory for test suites exceeding 3 minutes sequential execution time. Configure test runners to distribute across available workers with maximum 4x parallelisation factor to prevent resource exhaustion.

Security stage

The security stage performs automated security verification. Implementation details appear in Security and Compliance Testing; this section specifies pipeline integration requirements.

Check typeTool categoryGate policyMaximum duration
Static analysis (SAST)Semgrep, SonarQube, CodeQLBlock on high/critical10 minutes
Dependency scanTrivy, Snyk, OWASP Dependency-CheckBlock on critical CVE5 minutes
Secret detectionGitleaks, TruffleHogBlock on any detection2 minutes
Container scanTrivy, GrypeBlock on critical CVE5 minutes
IaC scanCheckov, tfsecBlock on high severity3 minutes

Security findings produce machine-readable output in SARIF format for aggregation in security dashboards. Pipeline logs must not contain finding details that could aid attackers; findings route to secure reporting channels.

Artifact stage

The artifact stage stores, signs, and catalogues build outputs for deployment.

RequirementSpecification
Storage locationOrganisation-controlled registry (not public registries for production artifacts)
Naming convention{project}/{component}:{semver}-{short-sha}
SignatureCosign or Notary signature with organisation signing key
RetentionDevelopment: 7 days, Staging: 30 days, Production: 1 year minimum
MetadataBuild provenance attestation in SLSA format
Vulnerability scanScan stored artifact, not just build output

Artifact immutability is mandatory. Once published to a registry with a specific tag, that tag must never be overwritten. The latest tag is prohibited for production deployments.

Environment model

Environments provide isolated deployment targets with distinct purposes and access controls. Code promotes through environments sequentially; no environment may be bypassed except under documented emergency procedures.

+--------------------------------------------------------------------+
| ENVIRONMENT PROMOTION MODEL |
+--------------------------------------------------------------------+
| |
| +----------------+ +----------------+ +----------------+ |
| | | | | | | |
| | DEVELOPMENT +---->+ STAGING +---->+ PRODUCTION | |
| | | | | | | |
| +-------+--------+ +-------+--------+ +-------+--------+ |
| | | | |
| v v v |
| +----------------+ +----------------+ +----------------+ |
| | Auto-deploy on | | Deploy on | | Deploy on | |
| | merge to main | | staging | | production | |
| | | | approval | | approval | |
| | No approval | | | | | |
| | required | | QA team | | Release | |
| | | | approval | | manager + PO | |
| +----------------+ +----------------+ +----------------+ |
| |
| Duration in env: Duration in env: Deployment window: |
| Until next merge Minimum 24 hours Tue-Thu 09:00-16:00 |
| for non-critical (local time) |
| |
+--------------------------------------------------------------------+

Figure 2: Environment promotion with approval gates and timing constraints

Environment specifications

CharacteristicDevelopmentStagingProduction
PurposeIntegration testing, feature validationPre-production verification, UATLive service delivery
DataSynthetic only, reset weeklyAnonymised production subsetReal user data
Scale10% of production capacity50% of production capacityFull capacity with headroom
Availability targetBest effort, business hours99% during business hoursPer SLA (99.5% minimum)
AccessDevelopment teamDevelopment + QA + selected stakeholdersOperations team only
Deployment frequencyOn every merge (10-50/day typical)1-5 deployments per day1-10 deployments per week
Rollback timeImmediate, automatedUnder 15 minutesUnder 5 minutes
MonitoringBasic health checksFull monitoring, alert to dev teamFull monitoring, 24/7 alerting
SecretsDevelopment secrets, rotated monthlyStaging secrets, rotated monthlyProduction secrets, rotated per policy

Environment parity

Production parity reduces deployment failures by ensuring staging behaviour predicts production behaviour. Maintain parity across these dimensions:

DimensionParity requirementAcceptable deviation
Operating systemIdentical versionPatch level within 30 days
Runtime versionIdenticalNone
Database versionIdentical major.minorPatch level within 30 days
Network topologyMatching architectureScale differences acceptable
Configuration schemaIdentical keysEnvironment-specific values expected
Third-party servicesSame providersSandbox vs production tiers acceptable
Geographic regionSame cloud region preferredDifferent region for DR testing acceptable

Deployment strategies

Deployment strategies control how new versions replace running versions. Strategy selection depends on rollback requirements, traffic patterns, and acceptable risk.

+-------------------------------------------------------------+
| DEPLOYMENT STRATEGIES |
+-------------------------------------------------------------+
| |
| 1. ROLLING UPDATE (Incremental Replacement) |
| (Gradually replace instances one by one) |
| |
| t=0 t=1 t=2 t=3 |
| +----+ +----+ +----+ +----+ |
| | v1 | | v2 | | v2 | | v2 | |
| | v1 | --> | v1 | --> | v2 | --> | v2 | |
| | v1 | | v1 | | v1 | | v2 | |
| +----+ +----+ +----+ +----+ |
| 100% v1 33% v2 66% v2 100% v2 |
| |
+-------------------------------------------------------------+
| |
| 2. BLUE / GREEN (Instant Switch) |
| (Two identical environments; switch the router) |
| |
| t=0 (Blue Active) t=1 (Switch to Green) |
| +------------+ +------------+ |
| | ROUTER |--+ | ROUTER |--+ |
| +------------+ | +------------+ | |
| | | | | |
| +----+ +----+ +----+ +----+ |
| | v1 | | v2 | | v1 | | v2 | |
| |BLUE| |GRN | |BLUE| |GRN | |
| +----+ +----+ +----+ +----+ |
| (Live) (Idle) (Idle) (Live) |
| |
+-------------------------------------------------------------+
| |
| 3. CANARY (Traffic Splitting) |
| (Route small traffic % to new version, then roll out) |
| |
| t=0 t=1 (Test) t=2 (Expand) t=3 |
| +----+ +----+ +----+ +----+ |
| | v1 | | v2 | | v2 | | v2 | |
| | v1 | --> | v1 | --> | v2 | --> | v2 | |
| | v1 | | v1 | | v1 | | v2 | |
| | v1 | | v1 | | v1 | | v2 | |
| +----+ +----+ +----+ +----+ |
| 100% v1 25% v2 50% v2 100% v2 |
| |
+-------------------------------------------------------------+

Figure 3: Traffic distribution patterns for rolling, blue-green, and canary deployments

Strategy specifications

StrategyRollback timeResource overheadDeployment durationBest for
Rolling update2-10 minutesMinimal (25% surge)5-15 minutesStateless services, frequent deploys
Blue-greenUnder 30 seconds100% (full duplicate)2-5 minutesCritical services, instant rollback required
Canary1-2 minutes10-50% additional30 minutes to 4 hoursHigh-risk changes, gradual validation
RecreateN/A (requires redeploy)None1-5 minutesDevelopment only, batch jobs

Rolling update configuration

Rolling updates replace instances incrementally while maintaining service availability.

# Kubernetes rolling update specification
spec:
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # Maximum 5 pods during update (4 + 1)
maxUnavailable: 0 # Never reduce below 4 available pods
minReadySeconds: 30 # Pod must be ready 30s before continuing
ParameterDevelopmentStagingProduction
maxSurge50%25%25%
maxUnavailable50%00
minReadySeconds103060
progressDeadlineSeconds300600900

Blue-green configuration

Blue-green deployments maintain two identical environments, with traffic switching between them atomically.

+------------------------------------------------------------------+
| BLUE-GREEN ARCHITECTURE |
+------------------------------------------------------------------+
| |
| +----------------+ |
| | LOAD | |
| | BALANCER | |
| +-------+--------+ |
| | |
| +---------------+---------------+ |
| | | |
| v v |
| +--------+--------+ +----------+------+ |
| | | | | |
| | BLUE (active) | | GREEN (idle) | |
| | Version 1.4.2 | | Version 1.5.0 | |
| | | | | |
| | +---+ +---+ | | +---+ +---+ | |
| | | | | | | | | | | | | |
| | +---+ +---+ | | +---+ +---+ | |
| | +---+ +---+ | | +---+ +---+ | |
| | | | | | | | | | | | | |
| | +---+ +---+ | | +---+ +---+ | |
| | | | | |
| +-----------------+ +-----------------+ |
| |
| After verification, swap load balancer target to GREEN |
+------------------------------------------------------------------+

Figure 4: Blue-green environment architecture with load balancer switch

Blue-green swap checklist (automated):

  1. Deploy new version to inactive environment
  2. Run smoke tests against inactive environment (internal endpoint)
  3. Run synthetic transactions against inactive environment
  4. Verify metrics collection functioning
  5. Switch load balancer target group
  6. Monitor error rates for 5 minutes
  7. If error rate exceeds 0.1%, automatic rollback to previous environment

Canary configuration

Canary deployments route a percentage of traffic to new versions, increasing gradually based on success metrics.

PhaseTraffic percentageDurationPromotion criteria
Initial5%15 minutesError rate under 0.1%, latency p99 within 10% of baseline
Expand25%30 minutesError rate under 0.1%, no alerts triggered
Majority50%60 minutesError rate under 0.05%, user feedback channels clear
Full100%PermanentCanary version becomes baseline

Automatic rollback triggers when any condition fails. Manual promotion gates may be inserted at any phase for high-risk changes.

Pipeline security

Pipeline infrastructure requires security controls equivalent to production systems, as pipelines have access to secrets, signing keys, and deployment credentials.

Secret management

Secret typeStorage locationAccess patternRotation frequency
API keysExternal secrets manager (Vault, AWS Secrets Manager)Injected at runtime, never in logs90 days
Signing keysHardware Security Module or managed KMSReference only, never exportedAnnual
Database credentialsExternal secrets managerShort-lived tokens preferred30 days
Cloud credentialsWorkload identity (no static keys)Federated authenticationN/A (no static credential)
Registry credentialsExternal secrets managerScoped to specific repositories90 days

Prohibited practices:

  • Secrets in repository (including encrypted secrets in git)
  • Secrets in pipeline configuration files
  • Secrets passed as command-line arguments (visible in process lists)
  • Secrets in build logs (mask all secret values)
  • Long-lived static credentials when workload identity is available

Runner security

CI/CD runners execute arbitrary code from repositories. Runner configuration must limit blast radius.

Runner typeUse caseSecurity model
Ephemeral containerStandard buildsNew container per job, destroyed after
Ephemeral VMBuilds requiring elevated privilegesNew VM per job, destroyed after
Persistent runnerSpecialised hardware (mobile builds)Isolated network, restricted repository access
Self-hosted runnerAir-gapped or on-premises requirementsHardened OS, no internet egress

Runner hardening requirements:

  • No persistent storage between jobs
  • No network access to production systems
  • Limited egress to approved registries and package repositories
  • Resource quotas preventing denial of service
  • Execution timeout of 60 minutes maximum

Feature flags and progressive delivery

Feature flags decouple deployment from release, enabling code to reach production before functionality activates for users. Progressive delivery extends this pattern to gradually expose features based on defined criteria.

+-------------------------------------------------------------+
| FEATURE FLAG LIFECYCLE |
+-------------------------------------------------------------+
| |
| DECOUPLING DEPLOYMENT FROM RELEASE |
| (Code is shipped to production, but hidden behind config) |
| |
| Step A: Deploy Code Step B: Toggle Flag |
| (Code dormant) (Feature Live) |
| |
| +--------------+ +--------------+ |
| | APP CODE | | APP CODE | |
| | [New Feat] | | [New Feat] | |
| +--------------+ +--------------+ |
| | | |
| v v |
| +--------------+ +--------------+ |
| | FLAG: OFF | | FLAG: ON | |
| +--------------+ +--------------+ |
| | | |
| (User sees Old) (User sees New) |
| |
+-------------------------------------------------------------+
| |
| PROGRESSIVE ROLLOUT STRATEGY |
| (Gradually increasing the user impact radius) |
| |
| Day 1 (0%) Day 2 (10%) Day 3 (25%) Day 7 (100%) |
| +----------+ +----------+ +----------+ +----------+ |
| | | |# | |### | |##########| |
| +----------+ +----------+ +----------+ +----------+ |
| Internal Staff / Beta Users General |
| Devs Only Canary Availability |
| |
+-------------------------------------------------------------+

Figure 5: Feature flag lifecycle from deployment through progressive rollout

Flag specifications

Flag typeLifespanOwnerCleanup deadline
Release flagTemporary (under 30 days)Product owner14 days after 100% rollout
Experiment flagTemporary (under 90 days)Product owner7 days after experiment conclusion
Ops flagPermanentEngineeringAnnual review
Permission flagPermanentProduct ownerAnnual review
Kill switchPermanentEngineeringNever remove

Stale flag policy: flags exceeding their expected lifespan by 30 days trigger automated alerts. Flags exceeding lifespan by 90 days require documented exception or removal.

Flag evaluation

Flag evaluation must not introduce latency or single points of failure.

Evaluation patternLatency impactAvailabilityUse case
Local evaluation (cached rules)Under 1msSurvives flag service outageProduction services
Remote evaluation (API call)10-50msDepends on flag serviceAdministrative tools
Edge evaluation (CDN)Under 5msHighFrontend applications

Default behaviour when flag service unreachable: flags return their designated default value, which must be the safe/conservative option (typically disabled for new features, enabled for kill switches).

Tooling reference

Pipeline platforms

PlatformLicenceHosting modelStrengthsConsiderations
GitLab CIMIT (core)Self-hosted or SaaSIntegrated with source control, comprehensive featuresResource intensive for self-hosting
Gitea ActionsMITSelf-hostedLightweight, GitHub Actions compatible syntaxSmaller ecosystem than GitHub
Woodpecker CIApache 2.0Self-hostedSimple, container-native, low resource requirementsLimited built-in integrations
JenkinsMITSelf-hostedExtensive plugin ecosystem, matureHigh maintenance burden, security track record
GitHub ActionsProprietarySaaSLarge marketplace, good documentationUS-headquartered (CLOUD Act), vendor lock-in
Azure DevOpsProprietarySaaS or ServerMicrosoft ecosystem integrationLicensing complexity, Microsoft account dependency

For organisations prioritising data sovereignty or operating in regions with US data concerns, self-hosted GitLab or Woodpecker CI provide full control over pipeline execution and logs.

Artifact registries

RegistryLicenceArtifact typesConsiderations
HarborApache 2.0Container images, Helm chartsFull-featured, supports replication, vulnerability scanning
Gitea packagesMITContainers, npm, PyPI, Maven, NuGetIntegrated with Gitea, lightweight
Nexus RepositoryEPL (OSS), Proprietary (Pro)UniversalMature, wide format support
ArtifactoryProprietaryUniversalEnterprise features, high cost
GitHub PackagesProprietaryContainers, npm, Maven, NuGetIntegrated with GitHub, US-hosted
AWS ECRProprietaryContainer imagesAWS integration, regional deployment

Feature flag services

ServiceLicenceHosting modelConsiderations
UnleashApache 2.0Self-hosted or managedFull-featured open source, good SDK coverage
FlagsmithBSD 3-ClauseSelf-hosted or managedOpen source, includes remote config
GrowthBookMITSelf-hosted or managedCombines flags with experimentation
LaunchDarklyProprietarySaaSEnterprise features, comprehensive SDKs, high cost
SplitProprietarySaaSStrong experimentation focus

Monitoring and observability

Pipeline observability enables identification of bottlenecks, flaky tests, and infrastructure issues before they impact delivery velocity.

Pipeline metrics

MetricTargetAlert thresholdMeasurement point
Lead time (commit to production)Under 4 hoursOver 24 hoursDeployment timestamp minus commit timestamp
Deployment frequencyDaily or moreUnder weeklyCount of production deployments
Change failure rateUnder 5%Over 15%Failed deployments divided by total deployments
Mean time to recoveryUnder 1 hourOver 4 hoursIncident duration for deployment-caused outages
Pipeline success rateOver 95%Under 85%Successful runs divided by total runs
Pipeline duration (p95)Under 15 minutesOver 30 minutesEnd-to-end pipeline execution time
Queue timeUnder 2 minutesOver 10 minutesTime from trigger to execution start

Build metrics

MetricTargetInvestigation trigger
Build cache hit rateOver 60%Under 40% for 3 consecutive days
Test flakiness rateUnder 1%Over 3% for any test
Security finding resolution timeUnder 7 days (critical)Over 14 days
Artifact size growthUnder 10% month-over-monthOver 25% growth

Dashboards must display these metrics at team, project, and organisation levels. Weekly review of pipeline metrics identifies degradation trends before they impact delivery.

See also