azurecontinuous-integrationazure-pipelinesrepository

Define Azure Pipeline For Multi-Repos


I have a project in Azure that has many repositories. All of the repositories need to run with the same pipeline, so I'm looking for a way to define the repository name as a variable.

Here's an example of what I'm trying to achieve:

trigger:
- master

pool:
  name: 'xxxx'

variables:
  repoName: 'repoA'

resources:
  repositories:
    - repository: repo
      type: git
      name: '50aa1c1f-21f0-4c61-8d85-d83218e705c9/$(repoName)'

steps:
- checkout: self
- checkout: repo

- script: echo Hello, world!
  displayName: 'Run a one-line script'

Does anyone have any idea how to get this to work?


Solution

  • I have a project in Azure that has many repositories. All of the repositories need to run with the same pipeline, so I'm looking for a way to define the repository name as a variable.

    It's not supported to use variable as the repository name in Yaml resource. Please check the doc below:

    enter image description here

    If you would like to checkout multiple repo, and define reponame in variable, as an alternative, you can use checkout task.

    - checkout: git://projectname/${{ variables.repoName}}@${{ variables.branchRef }}
    

    It's mentioned in doc: enter image description here

    Please check similar ticket for the details.

    Edit:

    In my case there are dozens of repos, we won't be able to define and mange a pipeline for each repository.

    You can use parameter to define the reponame and use each loop for checkout task.

    parameters:
      - name: repoNames
        type: object
        default:
          - repo1
          - repo2
          - repo3
    
    steps:
    - checkout: self
    
    - ${{ each repo in parameters.repoNames }}:
      - checkout: git://myproject/${{repo}}
    

    It checks out all repos:

    enter image description here

    If you have different project name used with different repo name, you can use nested in parameters, my sample here.