I'm not sure since you didn't show your YAML file, but did you use checkout step:
resources:
repositories:
- repository: devops
type: github
name: kmadof/devops-templates
endpoint: kmadof
steps:
- checkout: self
- checkout: devops
- script: |
echo $(Build.SourcesDirectory)
ls $(Build.SourcesDirectory) *
- template: templates/template.yaml@devops
parameters:
repo: devops-templates
Above script checout two repos. In devops-templates
I have template which is used in main build yaml file (located in self
repo).
Please take a look also here
EDIT
I work a bit with this and tried few things. Let me describe first relation between files:
- build.yaml (main repo)
- templates/start.yml (template repo - template with stages)
- job one - templates/process.yaml (template repo)
- steps - templates/another-template.yaml (template repo)
- job two - steps directly defined in start.yaml
And you don't have to actually checkout template repo because at running all templates are fecthed and build plan is created. You only need to checkout template repo if you are going to run some scripts (for instance powershell scripts). Here you have my yaml files:
build.yaml
resources:
repositories:
- repository: devops
type: github
name: kmadof/devops-templates
endpoint: kmadof
stages:
- template: templates/start.yaml@devops
parameters:
repo: devops-templates
buildSteps:
- checkout: self
- checkout: devops
- bash: echo Test #Passes
displayName: succeed
- bash: echo "Test"
displayName: succeed
start.yaml
# File: start.yml
parameters:
- name: repo # defaults for any parameters that aren't specified
default: ''
- name: buildSteps # the name of the parameter is buildSteps
type: stepList # data type is StepList
default: [] # default value of buildSteps
stages:
- stage: secure_buildstage
pool: Hosted VS2017
jobs:
- template: process.yaml
parameters:
pool: # this parameter is called `pool`
vmImage: ubuntu-latest # and it's a mapping rather than a string
- job: secure_buildjob
steps:
- script: echo This happens before code
displayName: 'Base: Pre-build'
- script: echo Building
displayName: 'Base: Build'
- ${{ each step in parameters.buildSteps }}:
- ${{ each pair in step }}:
${{ pair.key }}: ${{ pair.value }}
- script: echo This happens after code
displayName: 'Base: Signing'
process.yaml
parameters:
- name: 'pool'
type: object
default: {}
jobs:
- job: build
pool: ${{ parameters.pool }}
steps:
- template: another-template.yaml
parameters:
repo: devops-templates
another-template.yaml
parameters:
- name: repo # defaults for any parameters that aren't specified
default: ''
steps:
- pwsh: Write-Host 'Hello form another template'
Please take a look here:
Build job uses template from devops-template repo but I don't checkout repo in this job.
You may wonder why we can't have one checkout per build. And this is because each job can run a different agent.
Here you have few links:
Last remark, you really need to checkout repo with templates when you template calling a file from that repo. For instance:
steps:
- task: PowerShell@2
inputs:
filePath: /scripts/myscript.ps1
parameters: param1: '' stages: - stage: stage1
– Bamby