如何启用Azure管道使用Git签出子模块?

戴夫

在我们的Git项目中,我们在.gitmodules中定义了以下内容

[submodule "DBPkg"]
  path = DBPkg
  url = https://[email protected]/MainCo/OurProject/_git/DBPkg

构建Azure管道时,在“获取源”管道步骤(我正在使用“ Azure Repos Git”)中,我启用了签出子模块的功能

在此处输入图片说明

在我们的项目设置中,我还进行了以下配置...

在此处输入图片说明

但是,在构建项目时,尝试通过以下方式检出子模块时,它会死掉...

2020-10-16T20:29:44.9912145Z HEAD is now at e06abce Modified docker file to remove unnecessary container name.
2020-10-16T20:29:44.9913415Z ##[command]git submodule sync
2020-10-16T20:29:44.9920288Z ##[command]git -c http.https://[email protected]="AUTHORIZATION: bearer ***" submodule update --init --force
2020-10-16T20:29:44.9923206Z Submodule 'DBPkg' (https://[email protected]/MainCo/OurProject/_git/DBPkg) registered for path 'DBPkg'
2020-10-16T20:29:44.9923842Z Cloning into '/home/vsts/work/1/s/DBPkg'...
2020-10-16T20:29:44.9924246Z remote: TF401019: The Git repository with name or identifier DBPkg does not exist or you do not have permissions for the operation you are attempting.
2020-10-16T20:29:44.9924850Z fatal: repository 'https://dev.azure.com/MainCo/OurProject/_git/DBPkg/' not found
2020-10-16T20:29:44.9925716Z fatal: clone of 'https://[email protected]/MainCo/OurProject/_git/DBPkg' into submodule path '/home/vsts/work/1/s/DBPkg' failed
2020-10-16T20:29:44.9926288Z Failed to clone 'DBPkg'. Retry scheduled
2020-10-16T20:29:44.9926718Z Cloning into '/home/vsts/work/1/s/DBPkg'...
2020-10-16T20:29:44.9927132Z remote: TF401019: The Git repository with name or identifier DBPkg does not exist or you do not have permissions for the operation you are attempting.
2020-10-16T20:29:44.9928020Z fatal: repository 'https://dev.azure.com/MainCo/OurProject/_git/DBPkg/' not found
2020-10-16T20:29:44.9928801Z fatal: clone of 'https://[email protected]/MainCo/OurProject/_git/DBPkg' into submodule path '/home/vsts/work/1/s/DBPkg' failed
2020-10-16T20:29:44.9929412Z Failed to clone 'DBPkg' a second time, aborting

我还需要做些什么才能授予管道步骤以检出子模块的权限?.gitmodules中的URL是从Repos部分直接剪切和粘贴的,通常我们会在该仓库中克隆该存储库。

Edit: The URLs for the repos in questions as copied from the portals are

https://[email protected]/MainCo/OurProject/_git/MainAPIs
https://[email protected]/MainCo/OurProject/_git/DBPkg

So the submodule lives at https://[email protected]/MainCo/OurProject/_git/DBPkg but not sure how to phrase the above in terms of a Git submodules.

Edit 2:

In response to the answer given, here is the error output reported by the agent ...

...
2020-10-20T13:21:23.9543308Z ##[command]git submodule sync
2020-10-20T13:21:23.9892501Z ##[command]git -c http.https://[email protected]="AUTHORIZATION: bearer ***" submodule update --init --force
2020-10-20T13:21:24.0147532Z Submodule 'DBPkg' (https://[email protected]/MainCo/OurProject/_git/DBPkg) registered for path 'DBPkg'
2020-10-20T13:21:24.0194148Z Cloning into '/home/vsts/work/1/s/DBPkg'...
2020-10-20T13:21:24.1694357Z remote: TF401019: The Git repository with name or identifier DBPkg does not exist or you do not have permissions for the operation you are attempting.
2020-10-20T13:21:24.1696067Z fatal: repository 'https://dev.azure.com/MainCo/OurProject/_git/DBPkg/' not found
2020-10-20T13:21:24.1726598Z fatal: clone of 'https://[email protected]/MainCo/OurProject/_git/DBPkg' into submodule path '/home/vsts/work/1/s/DBPkg' failed
2020-10-20T13:21:24.1731117Z Failed to clone 'DBPkg'. Retry scheduled
2020-10-20T13:21:24.1760958Z Cloning into '/home/vsts/work/1/s/DBPkg'...
2020-10-20T13:21:24.3885945Z remote: TF401019: The Git repository with name or identifier DBPkg does not exist or you do not have permissions for the operation you are attempting.
2020-10-20T13:21:24.3892068Z fatal: repository 'https://dev.azure.com/MainCo/OurProject/_git/DBPkg/' not found
2020-10-20T13:21:24.3902720Z fatal: clone of 'https://[email protected]/MainCo/OurProject/_git/DBPkg' into submodule path '/home/vsts/work/1/s/DBPkg' failed
2020-10-20T13:21:24.3909036Z Failed to clone 'DBPkg' a second time, aborting
2020-10-20T13:21:24.3987155Z ##[error]Git submodule update failed with exit code: 

1

PatrickLu-MSFT

Update2

Pipelines can access any Azure DevOps repositories in authorized projects, as described in the previous Limit job authorization scope to current project section, unless Limit job authorization scope to referenced Azure DevOps repositories is enabled.

With this option enabled, you can reduce the scope of access for all pipelines to only Azure DevOps repositories explicitly referenced by a checkout step in the pipeline job that uses that repository.

Try to turn off this option and check again.

If it's still not work, you need to check repo's security. Find your [project name] build service account and project collection build service account, make sure both of them have enough permission to access your two git repos.

在此处输入图片说明


Update

Try to use this in .gitmodules since submodule repo is in the same url as the parent. :

[submodule "DBPkg"]
  path = DBPkg
  url = ../DBPkg

You could also check this link: https://stackoverflow.com/a/34618962/5391065


The build pipeline will check out your Git submodules as long as they are:

  • Unauthenticated: A public, unauthenticated repo with no credentials required to clone or fetch.

  • Authenticated:

    1. 与上面指定的Git存储库包含在同一项目,GitHub组织或Bitbucket Cloud帐户中。

    2. 通过使用相对于主存储库的URL添加例如,将要签出git submodule add /../../submodule.git mymodule这一项:将不签出这一项:git submodule add https://dev.azure.com/fabrikamfiber/_git/ConsoleApp mymodule

您也可以在此处查看Azure DevOps文档

供您参考的类似博客:在(私有)Azure DevOps存储库中使用Git子模块

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章