azure-devops - Azure 管道中部署作业中的条件批准门

标签 azure-devops azure-pipelines azure-pipelines-yaml

由于条件批准在 azure yaml 管道中不起作用,我一直在尝试在部署阶段使用 2 环境的解决方法,如 yaml 所示。 使用工作条件和变量我想检查是否需要批准 但是当我运行管道时,我看到它仍在请求批准,即使条件不满足需要批准的部署作业。尽管需要批准的工作按预期跳过,但发布批准。我不明白为什么要请求批准。

  1. 在评估工作条件之前是否首先对某个阶段执行批准?
  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


skipped job but the check ran

更新: 如果我定义了 2 个阶段和相同的条件集,这会起作用,但这会在构建详细信息页面中显示我们不想要的 2 个阶段

另一个问题是 我们能否根据变量组中的变量值有条件地插入阶段模板

  • 阶段 ${{ifeq(变量['Policy_Approval_Required'],'true')}}:

最佳答案

支持条件插入模板,可以查看以下链接:https://github.com/microsoft/azure-pipelines-agent/issues/1749 .检查以下示例:

- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
  - template: sharedstep.yml@templates
    parameters:
       value: true

关于azure-devops - Azure 管道中部署作业中的条件批准门,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62614112/

相关文章:

Azure 应用程序见解显示 Node js 应用程序的重复日志条目

Linux 上的 Azure Web 应用程序 : "Error: Container didn' t respond to HTTP pings on port: 808 0"- when using: "start": "pm2 start server.js"

azure-pipelines - 使用 npm 任务与在 Azure 管道中使用脚本有什么区别?

selenium-webdriver - DevTools客户端实现: subscribing a listener to the already connected DevToolsClient

azure-devops - 多行 overrideValues Helm 安装 Azure DevOps

azure-devops - "Package or folder"在发布管道中的文件转换任务中指什么?

git - 无法使用 Visual Studio Team Services 设置 Web 应用程序的部署源...找不到带指纹的证书

azure - 如何在Azure DevOps管道池中请求多台代理机器?

powershell - 在 Yaml 管道中修复 PowerShell

azure - DotNetCoreCLI 可以构建解决方案吗?