Azure Pipeline Error: Could not find any file matching the template file pattern

Azure Pipeline Error: Could not find any file matching the template file pattern

作为代码在 Azure Pipeline 上工作,并尝试使用 YAML 管道通过 Azure 中的 ARM 模板创建资源。

在 Azure DevOps 中,我已将代码(部署 json、参数 json 和 yml 文件等)推送到功能分支下的 Azure Repos Git 中。

在 运行 管道时,由于 "csmFile" 值,我面临错误 "Error: Could not find any file matching the template file pattern"。

我的 yml 文件包含 ARM 模板部署信息,如下所示。

    trigger:
 branches:
    include:
    - dev-pipecode

pool:
  vmImage: 'windows-latest'

steps:

- task: AzureResourceManagerTemplateDeployment@3
  inputs:
    deploymentScope: 'Resource Group'
    azureResourceManagerConnection: 'company-development-Contributor'
    subscriptionId: 'XXXXXXXX'
    action: 'Create Or Update Resource Group'
    resourceGroupName: 'name of the resource group'
    location: 'North Europe'
    templateLocation: 'Linked artifact'
    csmFile: '$(System.DefaultWorkingDirectory)/AzureAuto/pipelineascode.json'
    csmParametersFile: '$(System.DefaultWorkingDirectory)/AzureAuto/param-pipelineascode.json'
    deploymentMode: 'Incremental'

我错过了什么吗?请指导我。谢谢。

首先,确认一下

根据您在任务中定义的 $(System.DefaultWorkingDirectory)/AzureAuto/pipelineascode.json,您需要确保 pipelineascode.json 在 repos 中的位置应该是这样的:

   Repository
    |    AzureAuto
    |    |   pipelineascode.json
    |    |   param-pipelineascode.json

这是我的存储库示例:


如果你的ARM模板库的结构确实符合上面提到的,现在我想它应该与你的分支有关。

您的 master 分支是否仍然包含 AzureAuto 文件夹和 pipelineascode.json/param-pipelineascode.json 文件?

您可以到build result您遇到构建错误信息的页面,确认分支名称是否是您存放ARM模板文件的名称:

至于为什么我这么猜,是因为系统会默认基于master分支构建而用户从new[=58=开始] YAML管道和首先 运行它。

此时,您需要azure-pipelines.yml文件从master分支复制到存储ARM模板文件的功能分支。

然后去 Pipelines => 打开相应的 YAML 构建 => 编辑 => 关注左上角并更改分支:

现在,此 YAML 管道应该构建在您存储 ARM 模板的正确分支上,并成功找到 JSON 文件。