Florent Valdelievre
Florent Valdelievre

Reputation: 1566

How to get repository name using multiple checkout

Is there any variable (environment, system, resources) in the pipeline that hold the value for foo_repo and bar_repo ? I am looking for the path (just/code/foo, and just/code/bar) as I don't want to duplicate it in the config.

$(Build.Repository.Name) will return the repo name for self but what about the other repositories ?

resources:
  repositories:
    - repository: foo_repo
      type: git
      name: just/code/foo
    - repository: bar_repo
      type: git
      name: just/code/bar

stages:
  - checkout: foo_repo
  - checkout: bar_repo
  - checkout: self

Upvotes: 4

Views: 4200

Answers (1)

jessehouwing
jessehouwing

Reputation: 114461

When you check out multiple repositories, some details about the self repository are available as variables. When you use multi-repo triggers, some of those variables have information about the triggering repository instead. Details about all of the repositories consumed by the job are available as a template context object called resources.repositories.

For example, to get the ref of a non-self repository, you could write a pipeline like this:

resources:
  repositories:
  - repository: other
    type: git
    name: MyProject/OtherTools

variables:
  tools.ref: $[ resources.repositories['other'].ref ]

steps:
- checkout: self
- checkout: other
- bash: |
    echo "Tools version: $TOOLS_REF"

https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#repository-details

The repositories context contains:

resources['repositories']['self'] =
{
    "alias": "self",
    "id": "<repo guid>",
    "type": "Git",
    "version": "<commit hash>",
    "name": "<repo name>",
    "project": "<project guid>",
    "defaultBranch": "<default ref of repo, like 'refs/heads/main'>",
    "ref": "<current pipeline ref, like 'refs/heads/topic'>",
    "versionInfo": {
        "author": "<author of tip commit>",
        "message": "<commit message of tip commit>"
    },
    "checkoutOptions": {}
}

Upvotes: 6

Related Questions