Pass a file reference as a parameter to a inserted step from another repo in a Azure YAML deployment

914 Views Asked by At

I have a repository of yaml based jobs that I'd like to reuse in a number of yaml script. The script that will use the jobs however are in other repository.

The reusable job takes a file path as an input parameter. And for some reason the file can't be found when the imported job executes by the pipeline.

How do I reference the file in the parameter from the main job so it can be found when executing the imported job?

# MyMainScriptTemplate.yml that will be executed by the pipeline 

trigger:
  - master
    
resources:
  repositories:
    - repository: AzureTemplates
    type: git
    name: AzureTemplates
    
jobs:
  - template: /FunctionApp/DeployFunctionApp.yml@AzureTemplates
  parameters:
    file: /Azure/Functions/template.json #This can be found when executing ...
# ReusableJobTemplate.yml defines a job that should be referenced from the main script

parameters:
  - name: file
  type: string
    
jobs:
  - job: DeployFunctionApp
  steps:
    - task: AzureResourceManagerTemplateDeployment@3
    inputs:
      deploymentScope: "Resource Group"
      azureResourceManagerConnection: "Dev"
      subscriptionId: "XYZ"
      action: "Create Or Update Resource Group"
      resourceGroupName: "XYZ"
      location: "West Europe"
      templateLocation: "Linked artifact"
      csmFile: ${{ parameters.file }}
      deploymentMode: "Incremental"
    displayName: "Run a one-line script"
1

There are 1 best solutions below

2
On BEST ANSWER

Please check how mulirepo behaves.

I would recommend you two steps:

  • add - checkout: AzureTemplates step before calling template
  • and change path from /Azure/Functions/template.json to (Agent.BuildDirectory)/AzureTemplates/Azure/Functions/template.json