Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional Approval gate in deployment jobs in azure pipelines

Since conditional approval doesn't work in azure yaml pipeline i've been trying a workaround using 2 environment in deployment stage, shown in yaml. using a conditions in job and a variable i want to check if approval required or not but when i run the pipeline , i see its still asking for approval even though the condition is not satisfied for the deployment job that requires approval. Post approval though the job that required approval skips as expected. I dont understand why its asking for approval.

  1. Are approval executed first for a stage before jobs conditions are evaluated?
  2. Did i miss something in the yaml?

trigger:
- none


variables:
 - group: pipelinevariables
   # Agent VM image name
 - name: vmImageName
   value: 'ubuntu-latest'

stages:

- stage: Deploy
  displayName: Deploy stage
  jobs:  
  - deployment: DeployWebWithoutApprval
    displayName: deploy Web App without approval
    condition: and(succeeded(),ne(variables.DEV_APPROVAL_REQUIRED,'true'))
    pool:
      vmImage: $(vmImageName)
    # creates an environment if it doesn't exist
    environment: 'app-dev'
    strategy:
      runOnce:
        deploy:
          steps:
          - script: echo No approval

  - deployment: DeployWebWithApprval
    displayName: deploy Web App with approval
    dependsOn: DeployWebWithoutApprval
    condition: and(eq(dependencies.DeployWebWithoutApprval.result,'Skipped'),eq(variables.DEV_APPROVAL_REQUIRED,'true'))
    pool:
      vmImage: $(vmImageName)
    # creates an environment if it doesn't exist
    environment: 'app-dev-with-approval'
    strategy:
      runOnce:
        deploy:
          steps:
          - script: echo requires approval


skipped job but the check ran

update : this works if i define 2 stages and and same set of conditions but that would show 2 stages in build details page which we don't want

Another question is Can we conditionally insert stage template based on variable value from variable group

  • stages ​${{ifeq(variables['Policy_Approval_Required'],'true')}}:
like image 679
Sanjeev Avatar asked Oct 31 '25 05:10

Sanjeev


1 Answers

Insert template conditionally is supported, you can check the following link: https://github.com/microsoft/azure-pipelines-agent/issues/1749. Check the following example:

- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
  - template: sharedstep.yml@templates
    parameters:
       value: true
like image 112
Cece Dong - MSFT Avatar answered Nov 03 '25 11:11

Cece Dong - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!