您可以在一個檔案中定義一組變數,並在其他檔案中多次使用它。
variables:
- template: string # Required as first property. Template file with variables.
parameters: # Parameters to map into the template.
參考此定義的定義:變數
性能
template 字串。 做為第一個屬性的必要屬性。
具有變數的範本檔案。
parameters 範本參數。
要對應至範本的參數。
範例
在此範例中,多個管線會重複一組變數。 變數只會指定一次。
# File: variables/build.yml
variables:
- name: vmImage
value: vs2017-win2016
- name: arch
value: x64
- name: config
value: debug
# File: component-x-pipeline.yml
variables:
- template: variables/build.yml # Template reference
pool:
vmImage: ${{ variables.vmImage }}
steps:
- script: build x ${{ variables.arch }} ${{ variables.config }}
# File: component-y-pipeline.yml
variables:
- template: variables/build.yml # Template reference
pool:
vmImage: ${{ variables.vmImage }}
steps:
- script: build y ${{ variables.arch }} ${{ variables.config }}