【问题标题】:How to use VSTS pipeline variable in YAML?如何在 YAML 中使用 VSTS 管道变量?
【发布时间】:2021-05-12 23:46:59
【问题描述】:

我在管道中定义了一个变量并将其设置为 false/true。但是,设置管道时,我可以看到parameters.RunUnitTest的值是$(RunUnitTest),这不是我在管道中设置的值。那么我在这里做错了什么?

trigger: none

extends:
  template: ThunderPipeline.yaml
  parameters:
      MergeBetweenBranches: true
      FromBranch: 'master'
      ToBranch: 'R_Current_Sprint'
      RunUnitTest: '$(RunUnitTest)'

【问题讨论】:

  • 愚蠢的我,看来我需要做这个变量['RunUnitTest']

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


【解决方案1】:

变量可以在一个 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'

【讨论】:

    猜你喜欢
    • 2019-01-27
    • 2022-07-21
    • 2020-11-07
    • 1970-01-01
    • 2019-10-04
    • 2021-08-31
    • 2023-03-19
    • 2019-04-29
    • 1970-01-01
    相关资源
    最近更新 更多