CI/CD Pipelines: Stages and Deployment Patterns

Stage design, promotions, manual approvals, and deployment strategy examples for safer delivery.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Core stage patterns

Build predictable multi-stage pipelines.

Multi-stage GitHub Actions workflow

Separate lint, test, build, and deploy into distinct jobs.

yamlANYstagesjobsdeploy
yaml
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm run lint

  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm test

  build:
    needs: [lint, test]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm run build

  deploy:
    needs: build
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - run: ./scripts/deploy.sh

Split work into jobs so failures are obvious and deploys cannot proceed before verification passes.

GitLab stage ordering

Use explicit stages for predictable progression.

yamlANYstagesgitlab
yaml
stages:
  - lint
  - test
  - build
  - deploy

deploy_production:
  stage: deploy
  script:
    - ./scripts/deploy.sh
  only:
    - main

In GitLab, jobs in later stages wait until earlier stages succeed unless you intentionally relax dependencies.

Always archive reports and clean up

Preserve artifacts even when the pipeline fails.

groovyANYjenkinsartifactsreports
groovy
post {
  always {
    junit 'reports/junit/*.xml'
    archiveArtifacts artifacts: 'dist/**', fingerprint: true
    cleanWs()
  }
}

`post` blocks keep reporting and cleanup consistent across success and failure states.

Deployment strategy snippets

Model common ways to ship safely.

Staging then production promotion

Require staging verification before production deploy.

yamlANYpromotionstagingproduction
yaml
jobs:
  deploy_staging:
    runs-on: ubuntu-latest
    steps:
      - run: ./scripts/deploy.sh staging

  smoke_test:
    needs: deploy_staging
    runs-on: ubuntu-latest
    steps:
      - run: ./scripts/smoke-test.sh https://staging.example.com

  deploy_production:
    needs: smoke_test
    runs-on: ubuntu-latest
    steps:
      - run: ./scripts/deploy.sh production

Promotion pipelines reduce risk by proving the same build in staging before releasing to production.

Manual production gate in GitLab

Add a human approval step before production deployment.

yamlANYmanualapprovalgitlab
yaml
deploy_production:
  stage: deploy
  script:
    - ./scripts/deploy.sh production
  when: manual
  only:
    - main

Manual gates are useful for high-risk environments or compliance-heavy teams.

Blue/green deploy flow

Switch traffic after health checks pass on the new environment.

bashANYblue-greenrelease
bash
./deploy-new-stack.sh
./run-health-checks.sh https://green.example.com
./switch-traffic.sh green
./monitor-release.sh

Blue/green is a deployment pattern rather than a platform feature. Encode the steps in your chosen CI/CD system.

Recommended next

No recommendations yet.