1
votes

Working on Azure Pipeline as code and trying to create a resource via ARM template in Azure using YAML pipeline.

In Azure DevOps, I have pushed the code (deployment json, parameter json and yml file etc) into Azure Repos Git under a feature branch.

While running the pipeline, I am facing the error "Error: Could not find any file matching the template file pattern" due to "csmFile" value.

my yml file contains ARM template deployment info as below.

    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'

Am I missing something? Please guide me. Thanks.

1

1 Answers

1
votes

Firstly, just for confirmation.

Based on this $(System.DefaultWorkingDirectory)/AzureAuto/pipelineascode.json you defined in the task, you need make sure the location of pipelineascode.json in repos should like this:

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

Here is the Repository sample of mine:

enter image description here


If the structure of your ARM template repository indeed respect above mentioned, now I guess it should relevant with your branch.

Does your master branch still contain AzureAuto folder and the pipelineascode.json/param-pipelineascode.json files?

You can go the build result page you encountered the build error message, and confirm whether the branch name is the one you stored the ARM template files:

enter image description here

As for why I guess so, it is because the system will build based on master branch by default while user start with the new YAML pipeline and first run it.

At this time, you need copy the azure-pipelines.yml file from master branch to that feature branch which stored ARM templates files.

Then go Pipelines => Open corresponding YAML build => Edit => Focus on upper left corner and change the branch:

enter image description here

Now, this YAML pipeline should build on the correct branch you stored the ARM templates and succeed to find the JSON file.