Azure DevOps - 多仓库检出

8

场景

  • 我的代码在一个代码库中,而我需要构建代码的所有依赖项位于另一个代码库(另一个项目)中。

以下是我的azure-pipelines.yml文件

# File: azure-pipelines.yml

pool:
  vmImage: 'ubuntu-latest'

variables:
  phpVersion: 7.3

resources:
  repositories:
    - repository: myLibraries
      type: git
      name: myProject/libraries

steps:
- checkout: self
- checkout: myLibraries
  path: libraries

- script: |
    sudo update-alternatives --set php /usr/bin/php$(phpVersion)
    sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
    sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
    sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
    sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
    php -version
  displayName: 'Use PHP version $(phpVersion)'

当我运行我的流水线时,出现以下错误:

不支持检出存储库“myLibraries”。仅支持“self”和“none”。不支持检出多个存储库。

参考资料:

https://github.com/microsoft/azure-pipelines-yaml/blob/master/design/multicheckout.md https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#using-other-repositories

3个回答

24

现在支持多仓库检出 - https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#multi-repo-checkout

resources:
  repositories:
  - repository: MyGitHubRepo # The name used to reference this repository in the checkout step
    type: github
    endpoint: MyGitHubServiceConnection
    name: MyGitHubOrgOrUser/MyGitHubRepo
  - repository: MyBitBucketRepo
    type: bitbucket
    endpoint: MyBitBucketServiceConnection
    name: MyBitBucketOrgOrUser/MyBitBucketRepo
  - repository: MyAzureReposGitRepository
    type: git
    name: MyProject/MyAzureReposGitRepo

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- checkout: self
- checkout: MyGitHubRepo
- checkout: MyBitBucketRepo
- checkout: MyAzureReposGitRepository

- script: dir $(Build.SourcesDirectory)

3
我无法从另一个项目中检出代码库。 - Alex Raj Kaliamoorthy
3
端点和名称参数是什么意思?我找不到任何带有实际值的示例。 - eddy

1
您发布的文本已经提供了答案:
多个存储库的检出不受支持。
如果您想在构建中使用多个存储库,您需要自己处理。
一些选项:
- 使用子模块或子树 - 具有 git clone 步骤,用于克隆第二个存储库 - 将第二个存储库的相关内容发布到工件存储库并根据需要还原它们
所有这些都有优缺点。

2
嗨@daniel,你对多仓库检出的Microsoft文档有何看法?它是否已经过时了?感谢你的帮助。 - sedrac
@sedrac 这是一份设计文档,即该功能实现的建议。 - Daniel Mann

0

我曾经遇到过同样的问题,提供的文档有点令人困惑。但我最终解决了它。

这是我的经验:

(对于自己的存储库的检出,在resources/repositories中不需要提及任何内容,我们需要提及其他想要检出的存储库)

资源:

存储库:

  • 存储库: myrepoAliasname

    类型: git

    名称: myActualreponame

    ref: refs/heads/mybranchname #我想要检出存储库中的特定分支

步骤:

  - checkout: self

  - checkout: myrepoAliasname (this is the name we gave in resources and it will checkout our mentioned branch of this repo)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接