【发布时间】: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