例如,考虑以下模板(例如,名为xyz.yml):
parameters:
projects: ['p1', 'p2', 'p3']
steps:
- ${{ each project in parameters.projects }}:
- task: VSBuild@1
displayName: Build ${{ project }}
inputs:
solution: ${{ project }}.sln
...
现在,假设我有以下azure-pipelines.yml文件:
...
steps:
...
- template: xyz.yml
parameters:
projects: ???
...
如何从构建变量中输入projects
模板参数?假设在构建时我只要求构建 p1 和 p3 。我该怎么办?
答案 0 :(得分:1)
您可以尝试使用stepList类型的参数,并将相同的参数值传递给模板。
例如:
main.yaml:
parameters:
- name: mySteplist
type: stepList
default:
- task: CmdLine@2
inputs:
script: |
echo Write your commands here
echo Hello world1
- task: CmdLine@2
inputs:
script: |
echo Write your commands here
echo Hello world2
trigger:
- none
steps:
- template: stepstem.yml
parameters:
buildSteps:
- ${{ parameters.mySteplist }}
# - template: stepstem.yml
# parameters:
# buildSteps:
# - bash: echo Test #Passes
# displayName: succeed
# - bash: echo "Test"
# displayName: succeed
# - ${{ parameters.mySteplist }}
- task: CmdLine@2
inputs:
script: |
echo Write your commands here
echo Hello world3
stepstem.yaml:
parameters:
- name: buildSteps # the name of the parameter is buildSteps
type: stepList # data type is StepList
default: []
steps:
- ${{ parameters.buildSteps }}
- task: CmdLine@2
inputs:
script: |
echo Write your commands here
echo Hello world tem
- script: echo "hello"
因此,您可以将VSBuild @ 1任务用作默认参数值,并可以在队列构建时更改它。
答案 1 :(得分:0)
检查以下示例:
#xyz.yml
parameters:
projects: []
steps:
- ${{ each project in parameters.projects }}:
- task: VSBuild@1
displayName: Build ${{ project }}
inputs:
solution: ${{ project }}.sln
...
...
#azure-pipelines.yml
steps:
- template: xyz.yml
parameters:
projects: ["p1", "p3"]