【问题标题】:Azure Pipelines YAML: Unexpected value 'variables' and Unexpected 'stages'Azure Pipelines YAML:意外的值“变量”和意外的“阶段”
【发布时间】:2020-12-02 12:09:36
【问题描述】:

我已经非常接近我的模板和使用它的部署 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'

任何帮助将不胜感激。我确定它就在我的鼻子前面,但我已经挣扎了好几天,所以我认为是时候寻求帮助了。

【问题讨论】:

标签: azure-devops yaml azure-pipelines


【解决方案1】:

意外的值“阶段”

您的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,所以你不能在jobs元素下引用stages模板。改变

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,工作/阶段支持它。将变量移动到正确的范围将解决此问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 2020-07-04
    • 2022-08-11
    • 2021-09-12
    • 1970-01-01
    • 2020-10-22
    • 1970-01-01
    相关资源
    最近更新 更多