我使用 Azure Pipelines 作为 Azure DevOps 的一部分。 我正在尝试在模板文件中定义变量,因为我需要多次使用相同的值。
这是我的stage-template.yml
:
parameters:
- name: param1
type: string
- name: param2
type: string
variables:
var1: path/${{ parameters.param2 }}/to-my-file.yml
stages:
- stage: Deploy${{ parameters.param2 }}
displayName: Deploy ${{ parameters.param1 }}
jobs:
...
当尝试使用此管道时,我收到一条错误消息:
/stage-template.yml (Line: 7, Col: 1): Unexpected value 'variables'
为什么这不起作用?我做错了什么?
最佳答案
模板中不能包含变量
作为阶段、作业或步骤模板(即包含在阶段
、作业
或管道中的 steps
元素)。您只能在变量模板中使用变量
。
遗憾的是,文档对此并不清楚。
包括舞台模板
# pipeline-using-stage-template.yml
stages:
- stage: stage1
[...]
# stage template reference, no 'variables' element allowed in stage-template.yml
- template: stage-template.yml
包括变量模板
# pipeline-using-var-template.yml
variables:
# variable template reference, only variables allowed inside the template
- template: variables.yml
steps:
- script: echo A step.
If you are using a template to include variables in a pipeline, the included template can only be used to define variables.
关于Azure 管道 YAML : Unexpected value 'variables' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60912733/