我在管道中定义了一个变量并将其设置为 false/true。但是在pipeline设置的时候可以看到parameters.RunUnitTest的值为$(RunUnitTest),这不是我在pipeline中设置的值。那么我在这里做错了什么?
trigger: none
extends:
template: ThunderPipeline.yaml
parameters:
MergeBetweenBranches: true
FromBranch: 'master'
ToBranch: 'R_Current_Sprint'
RunUnitTest: '$(RunUnitTest)'
答案 0 :(得分:0)
变量可以在一个 YAML 中定义并包含在另一个模板中。如果您想将所有变量存储在一个文件中,这可能很有用。如果您使用模板在管道中包含变量,则包含的模板只能用于定义变量。从模板扩展时,您可以使用步骤和更复杂的逻辑。当您想限制类型时,请使用参数而不是变量。
在本例中,变量 favoriteVeggie
包含在 azure-pipelines.yml
中。
# File: vars.yml
variables:
favoriteVeggie: 'brussels sprouts'
# File: azure-pipelines.yml
variables:
- template: vars.yml # Template reference
steps:
- script: echo My favorite vegetable is ${{ variables.favoriteVeggie }}.
或者类似的东西:
# File: templates/steps-with-params.yml
parameters:
- name: 'runExtendedTests' # defaults for any parameters that aren't specified
type: boolean
default: false
steps:
- script: npm test
- ${{ if eq(parameters.runExtendedTests, true) }}:
- script: npm test --extended
# File: azure-pipelines.yml
steps:
- script: npm install
- template: templates/steps-with-params.yml # Template reference
parameters:
runExtendedTests: 'true'