Azure Pipelines YAML:意外值“变量" [英] Azure Pipelines YAML: Unexpected value 'variables'
问题描述
我将Azure Pipelines用作Azure DevOps的一部分.我正在尝试在模板文件中定义变量,因为我需要多次使用相同的值.
I'm using Azure Pipelines as a part of Azure DevOps. I'm trying to define variables in my template file, because I need to use the same value multiple times.
这是我的 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:
...
尝试使用此管道时,出现错误消息:
When trying to use this pipeline, I get an error message:
/stage-template.yml(第7行,第1行):意外值变量"
/stage-template.yml (Line: 7, Col: 1): Unexpected value 'variables'
为什么这不起作用?我做错了什么?
Why is this not working? What did I do wrong?
推荐答案
您不能在管道中有参数,只能在templateReferences中:
you cant have parameters in the pipeline, only in the templateReferences:
name: string # build numbering format
resources:
pipelines: [ pipelineResource ]
containers: [ containerResource ]
repositories: [ repositoryResource ]
variables: # several syntaxes, see specific section
trigger: trigger
pr: pr
stages: [ stage | templateReference ]
如果要在模板中使用变量,则必须使用正确的语法:
if you want to use variables in templates you have to use proper syntax:
parameters:
- name: param1
type: string
- name: param2
type: string
stages:
- stage: Deploy${{ parameters.param2 }}
displayName: Deploy ${{ parameters.param1 }}
variables:
var1: path/${{ parameters.param2 }}/to-my-file.yml
jobs:
...
这篇关于Azure Pipelines YAML:意外值“变量"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!