gpt4 book ai didi

Azure 管道 YAML : Unexpected value 'variables'

转载 作者:行者123 更新时间:2023-12-03 17:24:57 35 4
gpt4 key购买 nike

我使用 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.

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#variable-reuse

关于Azure 管道 YAML : Unexpected value 'variables' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60912733/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com