Azure Pipelines YAML:意外的值“变量"和意外的“阶段" [英] Azure Pipelines YAML: Unexpected value 'variables' and Unexpected 'stages'

查看:65
本文介绍了Azure Pipelines YAML:意外的值“变量"和意外的“阶段"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经很接近我的模板和使用它的部署Yaml.但是我遇到了错误

I have gotten pretty close with my template and my deploy yaml that uses it. However I am getting to errors

意外值变量"意外的值阶段"

Unexpected value 'variables' Unexpected value 'stages'

我确定语法错误,但是我一生无法理解为什么.

I am sure I have the syntax wrong, but I can't for the life of me understand why.

这是我模板的开始

#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

And here is the deploy yaml that uses it

# 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'

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

any help would be appreciated. I am sure it's right in front of my nose but I've been struggling for days so I think it's time to ask for help.

推荐答案

意外值阶段"

您的 template.yml stages 定义了一个模板,而您在 jobs 元素下引用它.

Your template.yml defines a template for stages, while you're referencing it under jobs element.

多级管道的正确格式为:

The correct format of multi-stage pipeline is:

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 模板.更改

stages=>stage=>jobs=job, so you can't reference stages template under jobs element. Changing

jobs:
- template: template.yml@template

收件人

stages:
- template: template.yml@template

将解决此问题.

意外值变量"

如果变量用于整个管道,请将其移至 azure-pipelines.yml :

If the variables are for whole pipeline, move it into azure-pipelines.yml:

trigger:
- master

variables:
  tag: '$(Build.BuildId)'
  buildVmImage: 'ubuntu-latest'
  deployPool: 'deploy-pool'

如果变量用于一个特定阶段,则将其移至阶段:

If the variables are for one specific stage, move it under stage:

stages:
- stage: Build
  variables:
    variable1: xxx
    variable2: xxx
  jobs:
  - job: Build
    pool:
      vmImage: $(buildVmImage)
    steps:
    - checkout: self
      submodules: recursive

如果变量用于一项作业,请将其移至特定作业下:

If the variables are for one job, move them under specific job:

stages:
- stage: Build
  jobs:
  - job: Build
    pool:
      vmImage: $(buildVmImage)
    variables:
      variable1: xxx
      variable2: xxx
    steps:
    - checkout: self
      submodules: recursive

jobs 元素不支持 variables ,而job/stage支持它.将变量移至正确的范围将解决此问题.

The jobs element doesn't support variables, job/stage support it instead. Moving the variables to correct scope would resolve this issue.

这篇关于Azure Pipelines YAML:意外的值“变量"和意外的“阶段"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆