【问题标题】:azure devops yaml pipeline not setting the variablesazure devops yaml管道未设置变量
【发布时间】:2021-11-23 22:14:59
【问题描述】:

我有一个运行以下模板/变量的 yaml 管道:

    variables:
    - template: vars/global.yaml
    steps:
    - template: steps/debug-vars.yaml

这是 global.yaml:

variables:
  isMain:              ${{ eq(variables['Build.SourceBranch'], 'refs/heads/main') }}
  isProduction:        ${{ eq(variables['Build.SourceBranch'], 'refs/heads/production') }}
  isTag:               ${{ startsWith(variables['Build.SourceBranch'], 'refs/tags/v') }}
  isFork:              ${{ eq(variables['System.PullRequest.IsFork'], 'True') }}
  isPR:                ${{ eq(variables['Build.Reason'], 'PullRequest') }}
  isTrustedCode:       ${{ eq(variables.isFork, 'False') }}
  isScheduled:         ${{ eq(variables['Build.Reason'], 'Schedule') }}
  isTrustedCI:         ${{ and( eq(variables.isFork,'False'), eq(variables.isPR,'False'), eq(variables.isScheduled,'False') ) }}

debug-vars.yaml 使用以下代码检查 vars/global.yaml 中的值:

steps:
- bash: |
    echo ""
    echo "---------"
    echo "Debugging"
    echo "---------"
    echo  "isMain: ${{ variables.isMain }}"
    echo  "isProduction: ${{ variables.isProduction }}"
    echo  "Build.SourceBranch: ${{ variables['Build.SourceBranch'] }}"
  displayName: Debug - Branch Variables

但是当我从主分支运行 CD 管道时,Build.SourceBranch 已填充,而“isMain”未填充,知道为什么吗?

---------
Debugging
---------
isMain: 
isProduction: 
Build.SourceBranch: refs/heads/main
Finishing: Debug - Branch Variables

【问题讨论】:

    标签: azure azure-devops yaml


    【解决方案1】:

    修复是将 debug-vars.yaml 中的语法从:${{ variables.isMain }} 更改为 $(isMain)

    【讨论】:

      猜你喜欢
      • 2021-11-16
      • 1970-01-01
      • 2022-09-23
      • 2020-05-23
      • 2020-08-27
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      相关资源
      最近更新 更多