首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在yml文件(Azure管道)中设置条件参数: VAR不更新

在yml文件(Azure管道)中设置条件参数: VAR不更新
EN

Stack Overflow用户
提问于 2020-11-24 12:05:41
回答 1查看 1.1K关注 0票数 2

问题

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

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

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-24 12:39:06

请将variables.triggerRepoName改为variables['triggerRepoName']。它应该能解决你的问题。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64986143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档