如何解决Azure Pipelines YAML:意外的值“变量”和意外的“阶段”
我已经很接近我的模板和使用它的部署Yaml。但是我遇到了错误
意外值“变量” 意外的值“阶段”
我确定语法错误,但是我一生无法理解为什么。
这是我模板的开始
#File: template.yml
parameters:
- name: repositoryName
type: string
default: ''
variables:
tag: '$(Build.BuildId)'
buildVmImage: 'ubuntu-latest'
deployPool: 'deploy-pool'
stages:
- stage: Build
jobs:
- job: Build
pool:
vmImage: $(buildVmImage)
steps:
- checkout: self
submodules: recursive
这是使用它的部署Yaml
# Repo: Organization/Project
# File: azure-pipelines.yml
trigger:
- develop
- next
- master
resources:
repositories:
- repository: template
type: git
name: AzureDevOps/AzureDevOps
jobs:
- template: template.yml@template
parameters:
repositoryName: 'exampleName'
任何帮助将不胜感激。我确定它就在我的鼻子前,但是我已经挣扎了好几天,所以我认为是时候寻求帮助了。
解决方法
意外值“阶段”
当您在template.yml
元素下引用它时,您的stages
定义了jobs
的模板。
多级管道的正确格式为:
stages:
- stage: Build
jobs:
- job: Build
pool:
vmImage: $(buildVmImage)
steps:
- checkout: self
submodules: recursive
- job: Job2
pool:
vmImage: $(buildVmImage)
steps:
...
- stage: Deploy
jobs:
- job: Deploy
pool:
vmImage: $(buildVmImage)
steps:
...
stages => stage => jobs = job,因此您不能在stages
元素下引用jobs
模板。更改
jobs:
- template: template.yml@template
收件人
stages:
- template: template.yml@template
将解决此问题。
意外值“变量”
如果变量用于整个管道,请将其移至azure-pipelines.yml
:
trigger:
- master
variables:
tag: '$(Build.BuildId)'
buildVmImage: 'ubuntu-latest'
deployPool: 'deploy-pool'
如果变量用于一个特定阶段,则将其移至阶段:
stages:
- stage: Build
variables:
variable1: xxx
variable2: xxx
jobs:
- job: Build
pool:
vmImage: $(buildVmImage)
steps:
- checkout: self
submodules: recursive
如果变量用于一项工作,请将其移至特定工作:
stages:
- stage: Build
jobs:
- job: Build
pool:
vmImage: $(buildVmImage)
variables:
variable1: xxx
variable2: xxx
steps:
- checkout: self
submodules: recursive
jobs
元素不支持variables
,而工作/阶段支持它。将变量移至正确的范围将解决此问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。