【问题标题】:ADO pipelines - how to evaluate the value of a variable group at runtimeADO 管道 - 如何在运行时评估变量组的值
【发布时间】:2020-08-05 19:35:55
【问题描述】:

我有一个变量组,我想在其中运行表达式。也就是说,我想在运行时计算变量组的变量内容。

Variables_General 有一个名为 isMain 的变量,其内容为 $[contains(variables['Build.SourceBranch'], 'refs/heads/develop')]

variables:
  - group: Variables_General

...

condition: variables.isMain

但这并没有按预期工作。我尝试了各种双引号组合,使用 $[] 和 $()。我已经在变量值和变量引用方式中都试过了。它做两件事之一,说它不期望“$”或只是检测到变量有内容,因此是“真”

在运行时评估变量组的变量值中的代码的正确方法是什么?

【问题讨论】:

    标签: azure-devops azure-pipelines azure-pipelines-release-pipeline azure-pipelines-yaml azure-yaml-pipelines


    【解决方案1】:

    Yaml 引用了变量组,但无法解析表达式。 Yaml 将变量组中的$[contains(variables['Build.SourceBranch'], 'refs/heads/develop')] 视为字符。

    您可以在以下网站上提交建议:

    https://developercommunity.visualstudio.com/content/idea/post.html?space=21

    目前,您可以在变量中单独定义isMain变量:

    variables:
    - group: Variables_General
    - name: isMain 
      value: $[contains(variables['Build.SourceBranch'], 'refs/heads/master')]
    
    steps:
    - script: echo Hello!
      condition: eq(variables.isMain, true)
    

    【讨论】:

    猜你喜欢
    • 2022-01-19
    • 2023-01-20
    • 2016-09-04
    • 1970-01-01
    • 2017-03-25
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多