【问题标题】:Conditionally setting parameter in yml file (Azure pipeline): VAR not updating在 yml 文件(Azure 管道)中有条件地设置参数:VAR 未更新
【发布时间】:2021-03-07 05:08:57
【问题描述】:

问题

我想根据触发管道的分支有条件地设置一个参数。如果触发的分支是feature/automated-testing,我想设置一个等于“True”的参数。请参阅下面的代码。

我的pipeline.yml 文件的部分内容如下所示:

trigger:
  branches:
    include:
      - feature/automated-testing

...

# Global variables for the pipeline
variables:
  - name: "triggerRepoName"
    value: "$(Build.SourceBranchName)"


stages:
  # common stage. Docker build, tag and push
  - stage: BuildDockerImage
    displayName: "Build docker image"
    variables:
     ...

    jobs:
      - template: /templates/pipelines/my-prject.yml@templates
        parameters:
          ${{ if eq( variables.triggerRepoName, 'feature/automated-testing') }}:
            runTests: "True"
          ${{ if ne(variables.triggerRepoName, 'feature/automated-testing') }}:
            runTests: "False"

问题

当我从分支 feature/automated-testing 推送并“回显”Dockerfile 中的变量 runTests 时,它是空白的。我在条件语句中的语法有问题吗?

我认为错误在于有条件地设置变量的方式,因此我选择不提供 Dockerfile 或使用的其他 .yml 模板 .yml。

【问题讨论】:

    标签: docker azure-devops yaml azure-pipelines


    【解决方案1】:

    请将variables.triggerRepoName 更改为variables['triggerRepoName']。它应该可以解决您的问题。

    【讨论】:

    • 嗨。我正在尝试学习 YAML,我很好奇为什么这个解决方案有效,而 OP 的初始方法却没有?如果您可以分享一些对您的答案的见解,请这样做。谢谢。
    猜你喜欢
    • 2021-12-07
    • 2021-12-01
    • 2016-02-08
    • 2022-12-11
    • 1970-01-01
    • 2022-07-12
    • 2022-08-14
    • 1970-01-01
    • 2022-08-10
    相关资源
    最近更新 更多