0
votes

I want to reuse templates (via 'extends') that are stored in a Git repo in a different Azure organisation.

What is the best way of doing that? In this documentation it says that for Azure Repos no endpoint (service connection) is required: https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#repository-resource

But I guess since the target repo is in a different Azure org a service connection is still required?

Please advise on how to proceed.

PS. It is clear to me that I could write a pipeline that mirrors the whole repo or just the files into a repo in the same org so that I can reuse it from there. But this would be just my 2nd option that I would like to take. I would gladly accept some setup overhead if I could keep the single source principle for these templates.

1

1 Answers

1
votes

We need to create the service connection Azure Repos/Team Foundation Server and then we could reuse the template saved in another organization repository

Template file(test.yml):

jobs:
- job: AnotherOrgRepoTemplate
  steps:
  - task: PowerShell@2
    inputs:
      targetType: 'inline'
      script: |
        Write-Host "Hello World"

YAML build definition:

trigger: none

pool:
  vmImage: ubuntu-latest

resources:
  repositories:
  - repository: AnotherOrg # The name used to reference this repository in the checkout step
    type: git
    endpoint: AnotherOrgRepo  #Service connection name
    name: test/test.git  #project name/repo name

jobs:
  - template: test.yml@AnotherOrg
  - job: Test
    steps:
      - checkout: AnotherOrg
      - checkout: self
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(Build.SourcesDirectory)'
          ArtifactName: 'drop'
          publishLocation: 'Container'


Result:

enter image description here