0

My issue

I have an Azure devops project with a template on another repository than main one's. I try to load the template but I get this:

/azure-pipelines.yml: File /TemplateRepository/build.yml not found in repository https://dev.azure.com/XXXXX/TestAzureDevops/_git/TemplateRepository branch refs/heads/main

What I did

build.yml is my template into repository: TemplateRepository.

azure-pipelines.yml is my main file.

this is my template:

parameters:
- name: 'name'
  default: 'name'
  type: 'string'


steps:
  - script: echo ${{parameters.name}}

This is my main:

pool:
  vmimage: 'windows-latest'

parameters:
  - name: contexts
    type: object
    default: [{
     name: macOS,
     pool: 'macOS-latest',
     sign: false
  },
  {
    name: Windows,
     pool: 'windows-latest',
     sign: true
  }]

resources:
  repositories:
    - repository: Tuto-Ressources
      ref: main
      type: git
      name: TemplateRepository

stages:
  - stage: BUILD
    jobs:
      - job: test
        steps:
          - checkout: self
          - checkout: Tuto-Ressources
          - script: dir 
            displayName: Dir

          - ${{ each context in parameters.contexts }}:
              - template: .\TemplateRepository\build.yml@Tuto-Ressources
                parameters:
                  name: ${{context.name}}
                  pool: ${{context.pool}}
                  sign: ${{context.sign}} 
                  buildSteps:
                    - checkout: self
                    - checkout: Tuto-Ressources
                    - bash: echo "Test module"

What I tested

If I remove the template lines from main script so I just have script: dir I can see my checkout on the VM and build.yml into \TemplateRepository directory.

So there is no reason it can't find my template.

I checked the branch name, it's main and I have no other one. I can see the file from the Devops Portal

What I need

I would like to understand what happen and what I can do. I know there are artifact, but in this situation I don't understand whay it is not working like this because I don't change job neither stage.

1 Answers1

1

The template line should reference the template file by its path relative to TemplateRepository. If your build template resides at \build.yml in TemplateRepository, then you should just do:

- template: build.yml@Tuto-Ressources

Also, you don't need to do - checkout: Tuto-Ressources - the pipeline engine will know to fetch the template file from referenced repository.

qbik
  • 5,502
  • 2
  • 27
  • 33