【问题标题】:Azure pipeline - specify branch name in multiple repositoryAzure 管道 - 在多个存储库中指定分支名称
【发布时间】:2026-01-19 20:30:02
【问题描述】:

作为Azure DevOps - Handling single release for separate code repositories for UI and Dotnet API layer 的延续,我正在尝试通过在存储库下定义多个存储库来检查我的 yaml 中的多个存储库,如下所示。我无法理解在哪里更改分支以确保我的结帐等任务不会发生在 master 上,而是发生在我的自定义分支上。

resources: 
repositories:
  - repository: mybitbucketrepo
    type: bitbucket
    endpoint: myserviceconnection
    trigger:  # CI trigger for this repository, no CI trigger if skipped (only works for Azure Repos)
      branches:
        include: [ custom-branch ]
    name: orgname/reponame

到目前为止,我尝试的内容如下,我得到了错误 - 仅支持“self”、“none”或存储库别名。任何帮助将不胜感激。

- checkout: mybitbucketrepo@custom-branch

【问题讨论】:

    标签: azure-devops azure-pipelines azure-pipelines-release-pipeline azure-pipelines-build-task azure-pipelines-yaml


    【解决方案1】:

    你需要定义ref设置:

    使用存储库资源时,请使用 ref 属性指定 ref。以下示例签出指定存储库的 features/tools/ 分支。

    resources:
      repositories:
      - repository: MyGitHubRepo
        type: github
        endpoint: MyGitHubServiceConnection
        name: MyGitHubOrgOrUser/MyGitHubRepo
        ref: features/tools
    

    然后只是

    steps:
    - checkout: MyGitHubRepo
    

    【讨论】:

    • @KeenUser 如果我的回复对您有帮助,您可以考虑支持一下吗?
    【解决方案2】:

    不支持使用@,请使用内联引用语法

    steps:
     - checkout: self
     - checkout: git://MyProject/MyToolsRepo@features/mytools
    

    通过附加@<ref>,可以指示代理检查不同的参考。在这种情况下,假设它是一个名为 features/mytools 的分支。分支也可以以refs/heads/ 为前缀,以明确它是一个分支。

    其他有效的参考(和类似参考的东西):

    • 参考/标签/
    • 提交 ID

    更多详情请看此链接:Multi-checkout: checking out multiple repos

    您也可以在资源中定义它,查看我们的官方文档 --Checking out a specific ref 示例如下:

    resources:
      repositories:
      - repository: app
        type: github
        name: org1/repoA
        ref: master
        endpoint: 'GitHub endpoint'
        trigger:
        - master
        - release/*
    

    【讨论】: