Search code examples
azure-devopsdeploymentazure-data-factoryazure-pipelines-yaml

Why I am receiving the error: Error: Template file pattern matches a directory instead of a file: /home/vsts/work/1/s in my yaml file pipeline file?


I have checked all the previous questions about this issue but I have not managed to resolve this issue. My YMAL pipeline file is the following:

trigger:
  branches:
    include:
      - deploy-dev
      - adf_publish

resources:
  repositories:
    - repository: CustodianDailyPipelines
      type: git
      name: 'CustodianDailyPipelines'
      ref: adf_publish

variables:
  workingDir: '$(Build.SourcesDirectory)'
  azureSubscription: 
  azureRMConnection: 
  resourceGroupDev: 'Dev'
  resourceGroupTest: 'Test'
  resourceGroupProd: 'Prod'
  sourceDataFactory: ''
  deployedDataFactory: ''
  region: 'westeurope'
  artifactName: 'arm-templates-artifact'
  vmImageName: 'ubuntu-latest'

stages:
- stage: Publish
  displayName: Publish
  jobs:
    - job: PublishJob
      displayName: Copy and Publish Artifacts
      pool:
        vmImage: $(vmImageName)
      steps:
        - checkout: self
        - checkout: CustodianDailyPipelines
          path: s/CustodianDailyPipelines
        - script: ls -l $(workingDir)/CustodianDailyPipelines
          displayName: 'List Source Directory Contents'
        - task: CopyFiles@2
          displayName: Copy files
          inputs:
            SourceFolder: '$(workingDir)/CustodianDailyPipelines/OstricaPipelines'
            Contents: '**/*.json'
            TargetFolder: '$(Build.ArtifactStagingDirectory)/ArmTemplates'
        - task: PublishBuildArtifacts@1
          displayName: Publish build artifacts
          inputs:
            PathtoPublish: '$(Build.ArtifactStagingDirectory)/ArmTemplates'
            ArtifactName: '$(artifactName)'
            PublishLocation: 'Container'

- stage: DeployDEV
  displayName: Deploy DEV stage
  condition: succeeded()
  jobs:
    - deployment: Deploy
      displayName: Deploy to DEV stage
      environment: 'development'
      pool:
        vmImage: $(vmImageName)
      strategy:
        runOnce:
          deploy:
            steps:
              - checkout: self
              - checkout: CustodianDailyPipelines
                path: a/CustodianDailyPipelines
              - download: none
              - task: DownloadPipelineArtifact@2
                inputs:
                  buildType: 'current'
                  artifactName: '$(artifactName)'
                  targetPath: '$(Pipeline.Workspace)/$(artifactName)'
              - script: |
                  echo "Listing all files in the artifact directory:"
                  ls -R $(Pipeline.Workspace)/$(artifactName)
                displayName: 'List all files in artifact directory'
              - script: |
                  echo "Contents of ARMTemplateForFactory.json:"
                  cat $(Pipeline.Workspace)/$(artifactName)/ARMTemplateForFactory.json
                  echo "Contents of ARMTemplateParametersForFactory.json:"
                  cat $(Pipeline.Workspace)/$(artifactName)/ARMTemplateParametersForFactory.json
                displayName: 'Verify ARM Templates'
              - task: AzureResourceManagerTemplateDeployment@3
                inputs:
                  deploymentScope: 'Resource Group'
                  azureResourceManagerConnection: $(azureRMConnection)
                  subscriptionId: $(azureSubscription)
                  action: 'Create Or Update Resource Group'
                  resourceGroupName: $(resourceGroupDev)
                  location: $(region)
                  templateLocation: 'Linked artifact'
                  csmFileLink: '$(Pipeline.Workspace)/$(artifactName)/ARMTemplateForFactory.json'
                  csmParametersFileLink: '$(Pipeline.Workspace)/$(artifactName)/ARMTemplateParametersForFactory.json'
                  overrideParameters: '-dataFactoryName $(deployedDataFactory) -environment development'
                  deploymentMode: 'Incremental'

I am utilizing these branches:

  • adf_publish to extract the ARM json templates of the data factory
  • deploy-dev: a feature branch based on the main branch which all the ADF resources and the yaml pipeline file.

Solution

  • If you expected to use the ARM template artifacts files downloaded into certain path in your pipeline agent, you should be using csmFile and csmParametersFile, rather than csmFileLink and csmParametersFileLink.

    Please modify and test with the sample YAML pipeline step instead.

    - task: AzureResourceManagerTemplateDeployment@3
      inputs:
        deploymentScope: 'Resource Group'
        azureResourceManagerConnection: '$(azureRMConnection)'
        subscriptionId: '$(azureSubscription)'
        action: 'Create Or Update Resource Group'
        resourceGroupName: '$(resourceGroupDev)'
        location: '$(region)'
        templateLocation: 'Linked artifact'
        csmFile: '$(Pipeline.Workspace)/$(artifactName)/ARMTemplateForFactory.json'
        csmParametersFile: '$(Pipeline.Workspace)/$(artifactName)/ARMTemplateForFactory.json'
        overrideParameters: '-dataFactoryName $(deployedDataFactory) -environment development'
        deploymentMode: 'Incremental'