skip to Main Content

I am trying to checkout repository in Azure pipeline which is different then self repo but in same Organization. Here repository name and project name will be passed as input parameter .

I have tried by following example in https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops but not able to pass with parameter.

I have tried with syntex as below, but not get success.

 resources:
   repositories:
   - repository: MyAzureReposGitRepository
     type: git
     name: $(project)/$(repo)
     ref: $(branch)

Also have tried like

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

But here getting error at time of running pipeline

The String must have at least one character. Parameter name:repositoryName

Please help if you have any other way to make it success.

2

Answers


  1. Since you are talking about parameters I’m assuming you are using templates. I was able to achieve the desired result with the following code

    # File: template.yml
    parameters:
    - name: project
      type: string
    - name: repo
      type: string
    - name: branch
      type: string
    
    stages:
    - stage: A
      displayName: Checkout
      jobs:
      - job: Checkout
        steps:
        - checkout: git://${{ parameters.project }}/${{ parameters.repo }}@${{ parameters.branch }}
    
    
    # File: pipeline.yml
    extends:
      template: template.yml
      parameters:
        project: ProjectName
        repo: RepoName
        branch: BranchName
    
    Login or Signup to reply.
  2. Checkout different Repository as per input in Azure Pipeline

    According to this thread Pipeline resource Version property as a variable:

    While we can’t allow variables in that field, this is an excellent use case for runtime parameters.

    So, we could not use variable $(project)/$(repo) in the resources.

    To resolve this issue, we could use the Checking out a specific ref:

    parameters:
    - name: ProjectName
      displayName: Project Name
      type: string
      default: LeoTest
      values:
      - LeoTest
    - name: repoName
      displayName: repo Name
      type: string
      default: TestRepo
      values:
      - TestRepo
    - name: branchRef
      displayName: Branch Name
      type: string
      default: Dev
      values:
      - Dev
    

    And

    - checkout: git://${{ parameters.ProjectName}}/${{ parameters.repoName}}@refs/heads/${{ parameters.branchRef}}
    

    The test result:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search