0
votes

I'm trying to deploy ARM with Azure DevOps. path to Git repo is "ARMTemplates\CreateSQLServerARM\azuredeploy.json" However I'm getting error. What could be wrong?

ERROR:

 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

Code: # Starter pipeline

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
  • script: | echo Add other tasks to build, test, and deploy your project. echo See https://aka.ms/yaml displayName: 'Run a multi-line script'
1

1 Answers

1
votes

The error indicates the azuredeploy.json file specified in parameter csmFile cannot be found.

When azure agent builds your pipeline, the repo source code is cloned in the default working folder ($(System.DefaultWorkingDirectory) ie. c:\agent_work\1\s) on the agent machine. If your repo is like below:

enter image description here

Then the folder structure is like below in the agent machine.

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

And the path for csmFile should be csmFile: 'Deploymentfiles\StorageAccount\azuredeploy.json'

However you can also use wildcard like below example, if you are not sure about the folders structure.

csmFile: '**\azuredeploy.json'

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

Update:

If the pipeline targets ubuntu agents. "/" should be used in the file path for csmFile field. ("\" is for the file path in windows system).

csmFile: 'ARMTemplates/CreateSQLServerARM/azuredeploy.json'

csmFile: '**/azuredeploy.json'

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