Azure Pipelines YAML: Unexpected value 'variables' and Unexpected 'stages'

六眼飞鱼酱① 提交于 2021-02-11 12:38:05

问题


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.

Here is the start of my template

#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

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.


回答1:


Unexpected value 'stages'

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, so you can't reference stages template under jobs element. Changing

jobs:
- template: template.yml@template

To

stages:
- template: template.yml@template

would resolve this issue.

Unexpected value 'variables'

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

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



来源:https://stackoverflow.com/questions/63381680/azure-pipelines-yaml-unexpected-value-variables-and-unexpected-stages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!