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
Multi-stage GitHub Actions workflow
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

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

GitLab stage ordering
stages:
  - lint
  - test
  - build
  - deploy

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

# Use explicit stages for predictable progression.

Always archive reports and clean up
post {
  always {
    junit 'reports/junit/*.xml'
    archiveArtifacts artifacts: 'dist/**', fingerprint: true
    cleanWs()
  }
}

# Preserve artifacts even when the pipeline fails.

## Deployment strategy snippets
Staging then production promotion
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

# Require staging verification before production deploy.

Manual production gate in GitLab
deploy_production:
  stage: deploy
  script:
    - ./scripts/deploy.sh production
  when: manual
  only:
    - main

# Add a human approval step before production deployment.

Blue/green deploy flow
./deploy-new-stack.sh
./run-health-checks.sh https://green.example.com
./switch-traffic.sh green
./monitor-release.sh

# Switch traffic after health checks pass on the new environment.

Recommended next

No recommendations yet.