由于有条件的批准在azure yaml管道中不起作用,因此我一直在尝试在部署阶段使用2环境进行变通,如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
更新: 如果我定义了2个阶段和相同的一组条件,则此方法有效,但是在我们不希望的构建详细信息页面中显示2个阶段
另一个问题是 我们能否根据变量组中的变量值有条件地插入舞台模板
答案 0 :(得分:0)
有条件地支持插入模板,您可以检查以下链接:https://github.com/microsoft/azure-pipelines-agent/issues/1749。检查以下示例:
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- template: sharedstep.yml@templates
parameters:
value: true
答案 1 :(得分:0)