如何使用多次签出获取存储库名称
How to get repository name using multiple checkout
管道中是否有任何变量(环境、系统、资源)保存 foo_repo 和 bar_repo 的值?我正在寻找路径 (just/code/foo, and just/code/bar) 因为我不想要在配置中复制它。
$(Build.Repository.Name)
将 return 作为 self
的存储库名称,但其他存储库呢?
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
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"
repositories
上下文包含:
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": {}
}
管道中是否有任何变量(环境、系统、资源)保存 foo_repo 和 bar_repo 的值?我正在寻找路径 (just/code/foo, and just/code/bar) 因为我不想要在配置中复制它。
$(Build.Repository.Name)
将 return 作为 self
的存储库名称,但其他存储库呢?
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
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"
repositories
上下文包含:
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": {}
}