使用 Azure DevOps 部署 ARM:找不到与模板文件模式匹配的任何文件

Deploying ARM with Azure DevOps: Could not find any file matching the template file pattern

我正在尝试使用 Azure DevOps 部署 ARM。 Git 回购的路径是 "ARMTemplates\CreateSQLServerARM\azuredeploy.json" 但是我收到错误。有什么问题吗?

错误:

 Checking if the following resource group exists: KensTestRG.
 Resource group exists: true.
 Creating deployment parameters.
 ##[error]Error: Could not find any file matching the template file pattern
 Finishing: AzureResourceGroupDeployment

代码: # 启动管道

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
-     task: AzureResourceGroupDeployment@2
  inputs:
    deploymentScope: 'Resource Group'
    ConnectedServiceName: 'AzureRmPipeline-conn'
    subscriptionId: '1111753a-501e-4e46-9aff-6120ed562222'
    action: 'Create Or Update Resource Group'
    resourceGroupName: 'KensTestRG'
    location: 'North Europe'
    templateLocation: 'Linked artifact'
    csmFile: 'ARMTemplates\CreateSQLServerARM\azuredeploy.json'
    deploymentMode: 'Incremental'
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

错误表示无法找到参数 csmFile 中指定的 azuredeploy.json 文件。

当 azure 代理构建您的管道时,repo 源代码被克隆到代理机器上的默认工作文件夹($(System.DefaultWorkingDirectory)c:\agent_work\s)。如果您的回购如下:

然后在代理机器中的文件夹结构如下。

s |
   - Deploymentfiles
     |
     - StorageAccount 
       |
       - **.json
   - VirtualNetwork
     |
      ...
   - readme.md

并且 csmFile 的路径应该是 csmFile: 'Deploymentfiles\StorageAccount\azuredeploy.json'

但是,如果您不确定文件夹结构,也可以像下面的示例那样使用通配符。

csmFile: '**\azuredeploy.json'

csmFile: '$(System.DefaultWorkingDirectory)\**\azuredeploy.json'

更新:

如果管道针对 ubuntu 代理。 csmFile 字段的文件路径中应使用“/”。 ("\"为windows系统中的文件路径)。

csmFile: 'ARMTemplates/CreateSQLServerARM/azuredeploy.json'

csmFile: '**/azuredeploy.json'

csmFile: '$(System.DefaultWorkingDirectory)/**/azuredeploy.json'