Azure Pipelines: "The step name version appears more than once. Step names must be unique within a job"
Azure Pipelines first puts every template into the pipeline and only then checks it. When two steps in one job end up with the same name:, the run does not start. Most often it is one steps template called twice in the same job.
What it looks like
Encountered error(s) while parsing pipeline YAML: Job Build: The step name version appears more than once. Step names must be unique within a job.
The line repeats for each extra copy. A typical case:
# azure-pipelines.yml
jobs:
- job: Build
steps:
- template: templates/fetch-tag.yml
parameters:
repo: api
- template: templates/fetch-tag.yml
parameters:
repo: front
# templates/fetch-tag.yml
parameters:
- name: repo
type: string
steps:
- pwsh: Write-Host "##vso[task.setvariable variable=TAG;isOutput=true]1.0.0"
name: version
The question on Stack Overflow has been opened about 33,000 times.
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. Its Pipelines tab (version 1.0.86 and later) lists the runs of the repositories you have open and opens a failed task's log in the editor, free to read.
Why
- A step's
name:is its ID: Microsoft's YAML reference calls it the "ID of the step" and allows letters, digits,-and_. Later steps read an output variable through it, as$(version.TAG), so two steps with one ID in a job are refused. - Templates are expanded before this check. The job then holds the template's steps once for each call, all with
name: version. Two different templates that both usename: versionin one job give the same error. displayNameis only the label in the run's log and may repeat. Steps withoutname:do not clash.
Build the name from a parameter
# templates/fetch-tag.yml
parameters:
- name: repo
type: string
steps:
- pwsh: Write-Host "##vso[task.setvariable variable=TAG;isOutput=true]1.0.0"
name: version_${{ parameters.repo }}
- Later steps then read
$(version_api.TAG)and$(version_front.TAG). Microsoft's page on setting variables in scripts describes this form: the step's name, a dot, the variable. - The parameter becomes part of an ID, so it should hold only letters, digits,
-and_. If the value you pass has other characters, add a separate parameter just for the name. - Steps made in a
${{ each }}loop need the same treatment: build the name from the loop's item.
Drop name: when nothing reads it
If no later step uses $(version.SOMETHING), remove name: from the template and keep a displayName for the log. The template can then be called as often as you like in one job.
The same with jobs
One level up, jobs are referred to by their job: ID, in dependsOn and in dependencies, so a jobs template used twice in a stage needs its ID from a parameter too. Microsoft's reference for a job allows only letters, digits and _ in it, not starting with a digit: job: build_${{ parameters.repo }} is not a valid ID for a repository called my-api, so pass a separate parameter for it.
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: ##_vso[ in the log · An output variable is empty in the next job or stage · Unexpected symbol or Unrecognized value within expression · The 'name' parameter value '$(VAR)' is not a valid Boolean · A template expression is not allowed in this context · Unexpected value 'variables', 'stages' or 'steps' · 日本語