Azure Pipelines: "File /templates/build.yml not found in repository"
Azure Pipelines reads the pipeline's YAML file and every template from the repository when the run is created, before any job or checkout. When a file is not where it looks, the run does not start, and the message says exactly where it looked: the full path, the repository and the branch. Put that next to where the file really is, and the cause is usually one of the cases below.
What it looks like
File azure-pipelines.yml not found in repository contoso/web-app at version/branch feature/login.
/pipelines/deploy.yml: File /pipelines/templates/build.yml not found in repository https://dev.azure.com/contoso/WebApp/_git/WebApp branch refs/heads/feature/login version 5b1e0c9a7f3d2e8b4c6a1f0e9d8c7b6a5f4e3d2c
- The first form comes from Run pipeline or Edit: the pipeline's own YAML file is not on that branch. The Run button can also stay grey for that branch.
- The second comes from a
template:line. The path before the colon is the file that has the line; afterFilecomes the full path Azure Pipelines built from it, then the repository, the branch and the commit it read. - The Stack Overflow question about the pipeline's own YAML file has been opened about 43,000 times, and the questions about templates with the same message about 28,000 times together.
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.
The pipeline's own YAML file
- The branch does not have it. A run uses the YAML file from the branch you run. A branch made from a branch where the YAML was never added fails like this, even when it runs on other branches. Merge the branch that has the file into it, or run a branch that has it.
- The file was renamed or moved. The pipeline keeps a YAML file path of its own. Microsoft's page on pipeline settings puts it under More actions on the pipeline's page, Settings, YAML file path, for when you move or rename the file. Check
.ymlagainst.yamland the letter case: Git paths are case sensitive. - A GitHub repository that worked before. In one answer, the GitHub service connection the pipeline used had been deleted in a cleanup; a new service connection fixed it. The repository and its connection are under Edit, More actions, Triggers, YAML, Get sources.
A template path is relative to the file that includes it
Microsoft's page on templates: a template path that starts with / is absolute within the repository; every other path is relative to the file that does the including, not to the repository root and not to the main pipeline file.
# /pipelines/deploy.yml steps: - template: templates/build.yml # looks for /pipelines/templates/build.yml - template: /templates/build.yml # looks for /templates/build.yml - template: ../templates/build.yml # also /templates/build.yml
The path after File in the message is the one it built, so a folder that appears twice or in the wrong place shows at once. Starting every template path with / avoids the question for files in the same repository.
A template in another repository
resources:
repositories:
- repository: templates # the alias after @
type: git
name: Platform/BuildTemplates # project/repository
ref: refs/heads/master
steps:
- template: build.yml@templates # path inside that repository, without its name
- The branch. Without
ref, the pipeline reads the other repository atrefs/heads/main(the templates page and the YAML schema), not at that repository's default branch. A template repository that only hasmastergivesbranch refs/heads/mainin the message. Setrefto a branch (refs/heads/name), a tag (refs/tags/name) or a commit. - No $(variables) in ref. The schema says the repository resource does not allow pipeline variables in
nameandref, but supports template expressions inref. To take the templates from the branch with the same name as the run's branch:ref: ${{ variables['Build.SourceBranch'] }}, which works only if the template repository has that branch. - The path. The path before
@is inside the template repository./BuildTemplates/build.yml@templateslooks for a folder called BuildTemplates in it. - A checkout does not help. The templates page says repositories are resolved once, when the pipeline starts, and templates must be there at the start of the run; you can't reference a template in an artifact. A
checkoutstep, a Git submodule or a downloaded artifact comes too late. Use a repository resource. - Another organization. A repository in another Azure DevOps organization needs
endpoint:with a service connection of type Azure Repos/Team Foundation Server that has access to it.
Inside an extends template from another repository
A pipeline that extends a template in a central repository runs that template's template: lines in the central repository, relative to the template's file. A file from the pipeline's own repository needs @self, which the templates page describes for this case:
- template: /templates/localized-build.yml@self
A variable in the template path
- template: $(TEMPLATE_FILE) looks for a file whose name is the text $(TEMPLATE_FILE), because templates are expanded before $() is replaced. Use a parameter or a variable written in the YAML with ${{ variables.TEMPLATE_FILE }}; the same timing is behind "is not a valid Boolean".
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: Unexpected value 'variables', 'stages' or 'steps' · A template expression is not allowed in this context · The 'name' parameter value '$(VAR)' is not a valid Boolean · Build validation · 日本語