4

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.

DreadedFrost
  • 2,602
  • 1
  • 11
  • 29
String_Chez
  • 111
  • 1
  • 2
  • 8
  • Duplicate of https://stackoverflow.com/questions/60912733/azure-pipelines-yaml-unexpected-value-variables – Avius Nov 11 '20 at 14:15

2 Answers2

15

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.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • that didnt work for me i still get /azure-pipelines.yml@automation (Line: 6, Col: 1): Unexpected value 'trigger' /azure-pipelines.yml@automation (Line: 9, Col: 1): Unexpected value 'variables' – itye1970 Apr 27 '22 at 13:16
0

I was having the same issue with 'variables'. Moving them from the template yaml to the actual pipeline yaml did the trick.