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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...