I have an azure template that I want to reuse in different projects. One of the templates is using a script (also stored in that template project), but the pipeline job can't find the script. Any idea what route do I need to put in the template repo
so other projects can find the script?
So the code is the following, this is the azure template in the Templates Repo:
> templates/my-template.yaml
---
steps:
- task: PowerShell@2
displayName: Run Script task
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
targetType: 'filepath'
filePath: ./scripts/my-script.ps1 # Can't find the path
And this is how I use it in the Project Repo:
resources:
...
- repository: mytemplates
type: git
name: MyTemplates
ref: refs/heads/main
...
stages:
- stage: Test
- jobs:
- steps:
- template: /templates/my-template.yaml@mytemplates
You have to use checkouts
to get the template in different repository as below:
- checkout: rithtemplates
- template: /templates/template.yaml@mytemplates
Where as in Filepath use:
filePath: $(Build.SourcesDirectory)/scripts/rith.ps1
Output:
Then the script will be executed: