Search code examples
azureazure-devopsazure-pipelinesdevopsazure-pipelines-yaml

How can we set parameters and variables in repositories?


This is just a sample structure. But I want to fetch data from parameters and variables. How can we do it so that I can reuse this for all the repositories (doing it for 50 repositories)?

    resources:
      repositories:
      - repository: {parameter}
        type: git
        name: ${parameter}
        ref: $(BranchName)
        trigger:
          - Develop
          - Release

Solution

  • Please note that set parameter and variable is not supported in repositories resources.

    Currently we are only able to use the parameter or variable for ref here. It's not supported for the repository and name. See resources.repositories.repository definition for details. enter image description here

    As a work around, we can add all the repositories as resources, and then set parameter and variable at the checkout step. Reference Check out multiple repositories in your pipeline.

    For example:

    parameters:
    - name: repository
      type: string
      default: myRepo1
      values:
      - myRepo1
      - myRepo2
      - myRepo3
    - name: reponame
      type: string
      default: myReponame1
      values:
      - myReponame1
      - myReponame2
    
    variables:
      BranchName : main
    
    
    resources:
      repositories:
      - repository: myRepo1
        type: git
        name: myReponame1
        ref: $(BranchName)
        trigger:
          - Develop
          - Release
      - repository: myRepo2
        type: git
        name: myReponame2
        ref: $(BranchName)
        trigger:
          - Develop
          - Release
    pool:
      vmImage: ubuntu-latest
    
    steps:
    - checkout: ${{parameters.repository}}
    

    However, the requirement makes sense, you could create a suggestion ticket via: https://developercommunity.visualstudio.com/report?space=21&entry=problem.