Azure Pipelines: "Unexpected value 'variables'" and the other Unexpected value errors
Azure Pipelines reads the YAML against its schema before anything runs. Unexpected value 'X' means the key X is not allowed at that point: in that kind of file, or at that indentation level. The message gives the file, line and column, so the question is only which file or level the key belongs to.
When the pipeline is a pull request's build validation, the pull request waits on it: Azure DevOps Pull Requests, a plugin for JetBrains IDEs, lists the pull request's branch policies with their state in IntelliJ IDEA, Rider or PyCharm, and with Pro runs a failed build policy again once the YAML is fixed. Get it on JetBrains Marketplace
What each file can hold
- The main pipeline file is one of four forms in Microsoft's YAML reference:
stages,jobs(one implicit stage),steps(one implicit job), orextends. Pipeline-wide keys such asname(the run number),trigger,pr,resourcesandparameterssit at its top. - A template holds one kind of content, with
parametersat its top: a steps template hassteps, a jobs templatejobs, a stages templatestages. Microsoft's page on templates says a template included for variables can only define variables. - Triggers can only be in the main file, not in a template (Microsoft's page on Azure Repos triggers).
The usual cases
Unexpected value 'variables'at the top of a steps, jobs or stages template: that top takes onlyparametersand its one kind of content. Put the variables undervariables:of a stage or job, or move them into a variables template (a file with onlyvariables) and include it there with- template: vars.yml. A variable group goes the same way: Microsoft's page on variable groups shows a variables template that holds- group: name, included under a stage'svariables:. Values for a steps template go in asparameters.Unexpected value 'stages':stagesin a file that already usesjobsorstepsat the top, or in a jobs or steps template. One file, one form; a stages template is included understages:.Unexpected value 'steps':stepsat the same level asjobs, or not indented under a- job:. Once a file hasjobs, each job holds its ownsteps.Unexpected value 'name'in a template:name, the run number, belongs to the main file. A template can set the number while the run goes, with the logging command##vso[build.updatebuildnumber]in a script step.- A task name such as
Unexpected value 'CmdLine@2': when the pipeline extends a template, that template may reject the task on purpose. Microsoft's page on templates shows an extends template that turns aCmdLine@2step into this error, so ask the template's owner which tasks it allows. Without such a template, the step has the task name as a key instead of- task: CmdLine@2.
# azure-pipelines.yml
name: $(Date:yyyyMMdd)$(Rev:.r)
trigger:
- main
variables:
- group: shared-settings
- template: vars.yml
jobs:
- job: build
steps:
- template: steps/build.yml
parameters:
configuration: Release
Azure DevOps pull requests in IntelliJ IDEA, Rider and PyCharm
Azure DevOps Pull Requests, a plugin by Lesstep for JetBrains IDEs 2024.1 or later and Android Studio, reads the organization, project and repository from your git remote and lists the pull requests that wait for your review in an IDE tool window, on Azure DevOps Services and on Azure DevOps Server. It shows the branch policies of a pull request with their state, so a required build that has not passed is next to its pull request, and with Pro you run a failed or expired build policy again from there. The review inbox is free; voting, commenting, completing and creating are Pro, with a 30-day trial.
Get it on JetBrains Marketplace
Azure DevOps and Azure Pipelines are trademarks of Microsoft Corporation; IntelliJ IDEA, Rider and PyCharm are trademarks of JetBrains s.r.o. This page is not affiliated with or endorsed by Microsoft or JetBrains.
More: A template expression is not allowed in this context · Build validation · 日本語