Search code examples
azure-devopsazure-pipelinesazure-pipelines-yamlazure-reposazure-devops-pipelines

Can Use other repositories yml file to other pipeline


Repo 1 and Branch Name: Repo1Branch

trigger:
- none

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: echo Hello, world!

I want to call Repo 1 form Repo 2 pipeline

Repo 2 and Branch Name: Repo2Branch

trigger:
- none

pool:
  vmImage: 'ubuntu-latest'

resources:
  repositories:
    - repository: templates
      type: git
      name: PROJECTNAME/Repo 1
      ref: Repo1Branch 
  
steps:
 - template: azure-pipelines.yml@Repo 1

Solution

  • Yes, you can it is mentioned here - Use other repositories

    In one repo you define template

    # Repo: Contoso/BuildTemplates
    # File: common.yml
    parameters:
    - name: 'vmImage'
      default: 'ubuntu 16.04'
      type: string
    
    jobs:
    - job: Build
      pool:
        vmImage: ${{ parameters.vmImage }}
      steps:
      - script: npm install
      - script: npm test
    

    and then you reference it

    # Repo: Contoso/LinuxProduct
    # File: azure-pipelines.yml
    resources:
      repositories:
        - repository: templates
          type: github
          name: Contoso/BuildTemplates
    
    jobs:
    - template: common.yml@templates  # Template reference
    
    

    but this has to be template. Not full pipeline. You cannot reference full pipeline as a template as you did above. So for instance trigger and pool are not allowed keywords in a template.