当前在Azure管道中,我们可以将要执行的作业列表传递给参数为jobList
的子模板,如doco中所示。
有没有一种方法可以封装来自pipeline.yml的这些作业,这些作业将被传递到另一个作业模板中的jobList
参数,然后将该模板传递给jobList
参数。我试图按如下方式构造管道:
pipeline.yml
deployment-template.yml
post-deploy-tests-dev.yml
post-deploy-smoke-tests-prod.yml
我想根据环境动态地将不同测试的作业插入deployment template
的末尾。我按照以下方式尝试了jobList
中的deployment-template.yml
类型的参数,但是它抛出一个错误,提示mapping not expected
。
#post-deploy-tests-dev.yml
jobs:
- job: Test1
steps:
- script: execute test1
#post-deploy-tests-smoke-tests-prod.yml
jobs:
- job: Test2
steps:
- script: execute test2
#pipeline.yml
...
- template: deployment-template.yml
parameters:
environment: dev
testsJobsList:
template: post-deploy-tests-dev.yml
- template: deployment-template.yml
parameters:
environment: prod
testsJobsList:
template: post-deploy-smoke-tests-prod.yml
#deployment-template.yml
parameters:
- name: testsJobsList
type: jobList
default: []
#All deployment jobs here
jobs:
...
...
#Tests as the end
- ${{ parameters.testsJobsList }}
是否可以动态传递jobList
?
答案 0 :(得分:0)
它抛出一个错误,提示不期望映射。
使用YAML示例进行测试,造成此问题的原因:在 pipeline.yml 文件(-
和{{1} })。在这个位置上,模板相当于一个工作,您需要添加- template: post-deploy-tests-dev.yml
。
这是我的样品:
pipeline.yml
- template: post-deploy-smoke-tests-prod.yml
deployment-template.yml
-
post-deploy-tests-dev.yml
trigger:
- none
pool:
vmImage: 'windows-latest'
jobs:
- template: deployment-template.yml
parameters:
testsJobsList:
- template: post-deploy-tests-dev.yml
- template: deployment-template.yml
parameters:
testsJobsList:
- template: post-deploy-smoke-tests-prod.yml
post-deploy-smoke-tests-prod.yml
parameters:
- name: 'testsJobsList'
type: jobList
default: []
jobs:
- ${{ each job in parameters.testsJobsList }}: # Each job
- ${{ each pair in job }}: # Insert all properties other than "steps"
${{ if ne(pair.key, 'steps') }}:
${{ pair.key }}: ${{ pair.value }}
steps: # Wrap the steps
- ${{ job.steps }} # Users steps
结果: