Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Pipelines YAML: Unexpected value 'variables'

I'm using Azure Pipelines as a part of Azure DevOps. I'm trying to define variables in my template file, because I need to use the same value multiple times.

This is my stage-template.yml:

parameters:
 - name: param1
   type: string
 - name: param2
   type: string

variables:
  var1: path/${{ parameters.param2 }}/to-my-file.yml

stages:
 - stage: Deploy${{ parameters.param2 }}
   displayName: Deploy ${{ parameters.param1 }}
   jobs:  
    ...

When trying to use this pipeline, I get an error message:

/stage-template.yml (Line: 7, Col: 1): Unexpected value 'variables'

Why is this not working? What did I do wrong?

like image 990
Draex_ Avatar asked Mar 29 '20 10:03

Draex_


1 Answers

you cant have parameters in the pipeline, only in the templateReferences:

name: string  # build numbering format
resources:
  pipelines: [ pipelineResource ]
  containers: [ containerResource ]
  repositories: [ repositoryResource ]
variables: # several syntaxes, see specific section
trigger: trigger
pr: pr
stages: [ stage | templateReference ]

if you want to use variables in templates you have to use proper syntax:

parameters:
 - name: param1
   type: string
 - name: param2
   type: string

stages:
- stage: Deploy${{ parameters.param2 }}
  displayName: Deploy ${{ parameters.param1 }}
  variables:
    var1: path/${{ parameters.param2 }}/to-my-file.yml
  jobs:  
  ...
like image 147
4c74356b41 Avatar answered Sep 24 '22 11:09

4c74356b41