azure-devops - 如何使用多次 checkout 获取存储库名称

标签 azure-devops azure-pipelines azure-pipelines-yaml

管道中是否有任何变量(环境、系统、资源)保存 foo_repo 和 bar_repo 的值?我正在寻找路径(just/code/foo 和 just/code/bar),因为我不想在配置中复制它。

$(Build.Repository.Name) 将返回 self 的 repo 名称,但其他存储库呢?

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"

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

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": {}
}

关于azure-devops - 如何使用多次 checkout 获取存储库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70744776/

相关文章:

azure - 使用托管代理通过 VSTS 发布管道部署 Service Fabric 应用程序

azure-devops - Azure DevOps 管道中 $(System.AccessToken) 中 token 的范围是什么

azure - 尝试将 PSRule 测试添加到 Azure Devops 管道。管道成功,但没有测试正在运行

json - 我收到 "There was an error while overriding ' ' 参数,因为 Azure Devops 中出现 'TypeError: Cannot read property ' type' of undefined' 错误

Azure DevOps管道错误: No builds currently exist in the pipeline definition supplied

azure - Azure YAML 管道出现错误无法完成部署

azure - 尝试在 Linux 虚拟机上的 Azure CLI 中创建虚拟机时出现响应错误

TFS/Visual Studio Online 生成定义备份

tfs - 如何增加在制品 (WIP) 限制

azure - 如何使用 Powershell 删除 Azure DevOps 旧构建管道及其租约