SuperAPI AI Directory

multi-stage-pipeline

Deployment & operations

View repository

Updated 10-15 21:33

About this skill

Multi-Stage Pipeline Skill

This is a skill for building Azure DevOps multi-stage pipelines.

Key Features

  • Multiple Stages: Build → Test → Deploy
  • Approval Gates: Manual approval
  • Parallel Execution: Simultaneous deployment to multiple environments
  • Conditional Branching: Conditions based on branch and environment
  • Deployment Strategy: Blue-Green、Canary

Complete Multi-Stage Pipeline

trigger:
  branches:
    include:
      - main
      - develop

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: Common-Variables

stages:
  # ビルドステージ
  - stage: Build
    displayName: 'Build Application'
    jobs:
      - job: BuildJob
        steps:
          - task: NodeTool@0
            inputs:
              versionSpec: '18.x'

          - script: |
              npm install
              npm run build
              npm test
            displayName: 'Build and Test'

          - task: PublishBuildArtifacts@1
            inputs:
              PathtoPublish: 'dist'
              ArtifactName: 'app'

  # テストステージ
  - stage: Test
    displayName: 'Run Tests'
    dependsOn: Build
    jobs:
      - job: UnitTests
        displayName: 'Unit Tests'
        steps:
          - script: npm run test:unit
            displayName: 'Run Unit Tests'

      - job: IntegrationTests
        displayName: 'Integration Tests'
        steps:
          - script: npm run test:integration
            displayName: 'Run Integration Tests'

      - job: E2ETests
        displayName: 'E2E Tests'
        steps:
          - script: npm run test:e2e
            displayName: 'Run E2E Tests'

  # セキュリティスキャン
  - stage: Security
    displayName: 'Security Scan'
    dependsOn: Build
    jobs:
      - job: SecurityScan
        steps:
          - task: WhiteSource@21
            inputs:
              cwd: '$(System.DefaultWorkingDirectory)'

  # Dev環境デプロイ
  - stage: Deploy_Dev
    displayName: 'Deploy to Dev'
    dependsOn: 
      - Test
      - Security
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/develop'))
    jobs:
      - deployment: DeployDev
        environment: 'Development'
        strategy:
          runOnce:
            deploy:
              steps:
                - task: AzureWebApp@1
                  inputs:
                    azureSubscription: 'Azure-Dev'
                    appName: 'myapp-dev'
                    package: '$(Pipeline.Workspace)/app'

  # Staging環境デプロイ
  - stage: Deploy_Staging
    displayName: 'Deploy to Staging'
    dependsOn: Deploy_Dev
    condition: succeeded()
    jobs:
      - deployment: DeployStaging
        environment: 'Staging'
        strategy:
          runOnce:
            preDeploy:
              steps:
                - script: echo "Pre-deployment validation"
            deploy:
              steps:
                - task: AzureWebApp@1
                  inputs:
                    azureSubscription: 'Azure-Staging'
                    appName: 'myapp-staging'
                    package: '$(Pipeline.Workspace)/app'
            routeTraffic:
              steps:
                - script: echo "Routing traffic"
            postRouteTraffic:
              steps:
                - task: InvokeRESTAPI@1
                  inputs:
                    connectionType: 'connectedServiceName'
                    serviceConnection: 'SmokeTests'
                    method: 'POST'
                    urlSuffix: '/run-smoke-tests'

  # Production環境デプロイ(承認必要)
  - stage: Deploy_Production
    displayName: 'Deploy to Production'
    dependsOn: Deploy_Staging
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
    jobs:
      - deployment: DeployProd
        environment: 'Production'  # 承認設定済み
        strategy:
          # Blue-Green デプロイ
          canary:
            increments: [10, 25, 50, 100]
            preDeploy:
              steps:
                - script: echo "Health check"
            deploy:
              steps:
                - task: AzureWebApp@1
                  inputs:
                    azureSubscription: 'Azure-Prod'
                    appName: 'myapp-prod'
                    package: '$(Pipeline.Workspace)/app'
                    deploymentMethod: 'zipDeploy'
            on:
              success:
                steps:
                  - script: echo "Deployment successful"
              failure:
                steps:
                  - script: echo "Rolling back"
                  - task: AzureAppServiceManage@0
                    inputs:
                      action: 'Swap Slots'
                      sourceSlot: 'staging'

Canary deployment

strategy:
  canary:
    increments: [10, 25, 50, 100]
    deploy:
      steps:
        - script: echo "Deploying $(strategy.increment)%"
        - task: AzureTrafficManager@1
          inputs:
            trafficPercentage: $(strategy.increment)

Version Information

  • Version: 1.0.0