Azure Pipelines YAML: Unexpected value 'variables'
Azure Pipelines YAML: Unexpected value 'variables'
Azure Pipelines YAML: Unexpected value 'variables'
Re: Azure Pipelines YAML: Unexpected value 'variables'
You can't have `variables` in a template that is included as a stage, job or step template (i.e. included below a `stages`, `jobs` or `steps` element in a pipeline). You can only use `variables` in a variable template.
The documentation sadly is not really clear about that.
**Including a stage template**
```
# pipeline-using-stage-template.yml
stages:
- stage: stage1
[...]
# stage template reference, no 'variables' element allowed in stage-template.yml
- template: stage-template.yml
```
**Including a variable template**
```
# pipeline-using-var-template.yml
variables:
# variable template reference, only variables allowed inside the template
- template: variables.yml
steps:
- script: echo A step.
```
If you are using a template to include variables in a pipeline, the included template can only be used to define variables.
[https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#variable-reuse](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#variable-reuse)
The documentation sadly is not really clear about that.
**Including a stage template**
```
# pipeline-using-stage-template.yml
stages:
- stage: stage1
[...]
# stage template reference, no 'variables' element allowed in stage-template.yml
- template: stage-template.yml
```
**Including a variable template**
```
# pipeline-using-var-template.yml
variables:
# variable template reference, only variables allowed inside the template
- template: variables.yml
steps:
- script: echo A step.
```
If you are using a template to include variables in a pipeline, the included template can only be used to define variables.
[https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#variable-reuse](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#variable-reuse)