Azure 管道 - 阶段条件取决于

标签 azure azure-devops azure-pipelines pipeline

我有三个环境:dev、hml 和 qa。

在我的管道中,根据分支,阶段有一个条件来检查它是否会运行:

- stage: Project_Deploy_DEV
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/dev')
  dependsOn: Project_Build

- stage: Project_Deploy_HML
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/hml')
  dependsOn: Project_Build

我正在做qa阶段,我想设置一个条件,根据分支,dependon参数会改变:

- stage: Project_QA
   condition:
     ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}:
       dependsOn: 'Project_Deploy_DEV'
     ${{ if eq(variables['Build.SourceBranchName'], 'hml') }}:
       dependsOn: 'Project_Deploy_HML'

但是,上述条件不起作用,有人知道执行此条件的最佳方法吗?

谢谢

最佳答案

从您的 YAML 示例来看,似乎存在格式问题。使用if表达式时,不需要在YAML中添加条件字段。

您可以尝试以下示例并检查它是否可以工作。

stages:
  - stage: A
    jobs:
      - job: test
        steps:
          - xxx

  - stage: B
    jobs:
      - job: test
        steps:
          - xxx
  - stage: C
    ${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
      dependsOn: A
    ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}:
      dependsOn: B  
    jobs:
      - job: test
        steps:
          - xxx

关于Azure 管道 - 阶段条件取决于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70406488/

相关文章:

azure - 使用 Azure Devops yaml 管道部署到本地服务器

国家云的 Azure Key Vault 域名

sql-server - Azure SQL Server 错误此版本的 SQL Server 不支持语句 'RECEIVE MSG'

postgresql - 为 ASP.NET Core 5.0 配置 PostgreSQL 连接字符串 - EF Core 5.0 Web 应用程序在 MS 或 Linux 云上运行?

azure - 在 Azure Kubernetes 服务 (AKS) 中,我有一个类型为 "ClusterIP"的服务,它是否在内部执行 Pod 的负载平衡?

powershell - 当 TLD 托管在 O365 上时,如何使用 POWERSHELL 创建 CNAME 记录?

azure - Visual Studio 在线构建和发布 - 将文件复制到另一个项目

git - 从构建中标记 git 版本 - 在 git 中找不到标记

azure - 从 Azure DevOps yaml 设置应用服务应用程序设置

python - 我需要 'requirements.txt' 文件还是应该安装依赖项? Azure 开发运营