Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 623
Florent Valdelievre Avatar asked Oct 18 '25 03:10

Florent Valdelievre


1 Answers

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": {}
}
like image 182
jessehouwing Avatar answered Oct 21 '25 11:10

jessehouwing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!