<t>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.<br/>
<br/>
The documentation sadly is not really clear about that.<br/>
<br/>
Including a stage template<br/>
<br/>
# pipeline-using-stage-template.yml<br/>
<br/>
stages:<br/>
- stage: stage1<br/>
[...]<br/>
# stage template reference, no 'variables' element allowed in stage-template.yml<br/>
- template: stage-template.yml <br/>
<br/>
```<br/>
<br/>
**Including a variable template**<br/>
<br/>
```<br/>
# pipeline-using-var-template.yml<br/>
<br/>
variables:<br/>
# variable template reference, only variables allowed inside the template<br/>
- template: variables.yml<br/>
<br/>
steps:<br/>
- script: echo A step.<br/>
<br/>
```<br/>
<br/>
If you are using a template to include variables in a pipeline, the included template can only be used to define variables.<br/>
<br/>
[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)</t>