skip to Main Content

In my pipeline template, I am checking out code from 2 different repos:

resources:
  repositories:
  - repository: DeploymentRepo
    type: git
    name: MyProject/AWS.Deployment
...
  steps:
    - checkout: self
    - checkout: DeploymentRepo

Which creates 2 directories. One is named for the "self" repo and the other for the "DeploymentRepo". I used $(Build.Repository.Name) to reference the name of the "self" repo for the path. Is there a way to reference the other repo directory? I can also use $(Build.Repository.LocalPath), but it only references the "self" repo. I want to reference the path to the "DeploymentRepo" using a variable. Do AZ pipelines support such a notion? I have read through this several times, but I see nothing obvious.

2

Answers


  1. No there isn’t such a variable. As suggested in the comments, using $(Build.SourcesDirectory)/DeploymentRepo or $(Pipeline.Workspace)/s/DeploymentRepo are the variables mostly used for this.

    Login or Signup to reply.
  2. When you checked multiple repos in the same jobs of a YAML pipeline, each repo generally will be checked out to the path "$(Build.SourcesDirectory)/<repo name>" by default.

    1. For the self repo where the YAML is hosted, you can use the predefined variable "Build.Repository.Name" to get the repo name.

    2. For each resource repos, you can use the repository resource variable "resources.repositories.<Alias>.name" to get the repo name.

      Note: For repository resource variables, you cannot directly reference them on the pipeline tasks using the expression like as "$(resources.repositories.<Alias>.name)", you need to first map them as the pipeline variables, and then reference the pipeline variables.

    See below example.

    resources:
      repositories:
      - repository: DeploymentRepo
        type: git
        name: MyProject/AWS.Deployment
    
    variables:
      DeploymentRepo.name: $[ resources.repositories.DeploymentRepo.name ]
    
    ...
      steps:
        - checkout: self
        - checkout: DeploymentRepo
    
        - task: Bash@3
          displayName: 'Show Infor'
          inputs:
            targetType: inline
            script: |
              echo "Build.Repository.Name = $(Build.Repository.Name)"
              echo "DeploymentRepo.name = $(DeploymentRepo.name)"
    
    # $(Build.Repository.Name) returns the name of the self repo.
    # $(DeploymentRepo.name) returns the name of resource repo.
    

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