TransWikia.com

Azure deploy pipeline with/without approval on separated enviroments

DevOps Asked by dr.linux on August 22, 2021

I have two separate environments under my repository:

  • development (Approvals are not configured but the environment exists)
  • production (Approvals rules are configured via dev.azure.com UI)

The problem is, even we try to deploy to the development environment, the pipeline asking for approval. How we can fix the issue? Below, you can see simple two deploy jobs from YAML:

jobs:
    - deployment: Deploy_Dev
      displayName: 'Deploy Develop to Dev Machine'
      pool:
        name: Development
      condition: contains(variables['Build.SourceBranch'], 'refs/heads/develop')
      environment: 'development'
      strategy:
        runOnce:
          deploy:
            steps:
              - checkout: none
              - task: Bash@3
                inputs:
                  targetType: 'inline'
                  script: |
                    echo $(hostname)
                  workingDirectory: '/var/www'
                  noProfile: false
                  noRc: false

    - deployment: Deploy_Master_to_Hotfix
      displayName: 'Deploy Master to Hotfix Machine'
      pool:
        name: Hotfix
      condition: contains(variables['Build.SourceBranch'], 'refs/heads/master')
      environment: 'production'
      strategy:
        runOnce:
          deploy:
            steps:
              - checkout: none
              - task: Bash@3
                inputs:
                  targetType: 'inline'
                  script: |
                      echo $(hostname)         
                  workingDirectory: '/var/www'
                  noProfile: false
                  noRc: false

One Answer

Environment approvals work per-stage. Split your jobs into separate stages:

stages:
  - stage: development
    condition: contains(variables['Build.SourceBranch'], 'refs/heads/develop')
    jobs:
    - deployment: Deploy_Dev
      displayName: 'Deploy Develop to Dev Machine'
      pool:
        name: Development
      environment: 'development'
      strategy:
        runOnce:
          deploy:
            steps:
              - checkout: none
              - task: Bash@3
                inputs:
                  targetType: 'inline'
                  script: |
                    echo $(hostname)
                  workingDirectory: '/var/www'
                  noProfile: false
                  noRc: false

  - stage: production
    condition: contains(variables['Build.SourceBranch'], 'refs/heads/master')
    jobs:
    - deployment: Deploy_Master_to_Hotfix
      displayName: 'Deploy Master to Hotfix Machine'
      pool:
        name: Hotfix
      environment: 'production'
      strategy:
        runOnce:
          deploy:
            steps:
              - checkout: none
              - task: Bash@3
                inputs:
                  targetType: 'inline'
                  script: |
                      echo $(hostname)         
                  workingDirectory: '/var/www'
                  noProfile: false
                  noRc: false

Answered by qbik on August 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP