I'm working on a multi-repo Azure DevOps setup involving two repositories (Repo1 and Repo2) in different projects, and I'm encountering issues with consistent path references when calling a PowerShell script from a shared YAML pipeline template.
The Setup:
Repo1 (Project1) contains:
A pipeline, pipeline1.yaml, which calls a YAML template, pipeline_template.yaml.
The template pipeline_template.yaml then calls a PowerShell script, script.ps1, located in helper_scripts/script.ps1.
Repo2 (Project2) contains:
- A pipeline, pipeline2.yaml, which calls the same pipeline_template.yaml from Repo1.
However, when I run pipeline2.yaml from Repo2, I get a "file not found" error for script.ps1 unless I use the path Repo1/helper_scripts/script.ps1 instead of helper_scripts/script.ps1.
Is there a way to set up a consistent or dynamic file path in pipeline_template.yaml that allows script.ps1 to be referenced correctly when called from both Repo1 and Repo2? I'd like to avoid hardcoding paths for each repository and keep the reference universal if possible. Any advice on how to structure the file paths or configure the pipeline templates to achieve this?
Thank you for any guidance!
pipeline_template.yaml:
- name: parameter1
type: string
- name: parameter2
type: string
jobs:
- job: Job1
steps:
- checkout: self
- task: AzureCLI@2
inputs:
azureSubscription: '$(GLOBAL_SERVICE_CONNECTION)'
scriptType: 'pscore'
scriptLocation: 'scriptPath'
scriptPath: 'helper_scripts/script.ps1'
arguments: '-WebhookURL "${{ parameters.parameter1 }}" -KeyVaultsToCheck "${{ parameters.parameter2 }}"'
env:
GLOBAL_SUBSCRIPTION: $(GLOBAL_SUBSCRIPTION)


checkout: git://project1/repo1with pathrepo1in yourpipeline_template.yamland changescriptPathto$(Agent.BuildDirectory)/repo1/helper_scripts/script.ps1. This is not a hard-coded path, but a new pathrepo1/is created in each pipeline that calls this template. In this case, no matter which repo or pipeline this template is used in, it will work as expected. Let me know if you have any other question.