如何启用我的 Azure 管道以使用 Git 签出子模块?
How do I enable my Azure pipeline to checkout a submodule using Git?
在我们的 Git 项目中,我们在 .gitmodules
中定义了以下内容
[submodule "DBPkg"]
path = DBPkg
url = https://MainCo@dev.azure.com/MainCo/OurProject/_git/DBPkg
构建 Azure Pipeline 时,在我的“获取源”管道步骤中(我使用的是“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://MainCo@dev.azure.com.extraheader="AUTHORIZATION: bearer ***" submodule update --init --force
2020-10-16T20:29:44.9923206Z Submodule 'DBPkg' (https://MainCo@dev.azure.com/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://MainCo@dev.azure.com/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://MainCo@dev.azure.com/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 部分剪切和粘贴。
编辑:从门户复制的问题中的回购 URL 是
https://MainCo@dev.azure.com/MainCo/OurProject/_git/MainAPIs
https://MainCo@dev.azure.com/MainCo/OurProject/_git/DBPkg
所以子模块位于 https://MainCo@dev.azure.com/MainCo/OurProject/_git/DBPkg 但不确定如何用 Git 子模块来表达上述内容。
编辑 2:
针对给出的答案,这里是代理报告的错误输出...
...
2020-10-20T13:21:23.9543308Z ##[command]git submodule sync
2020-10-20T13:21:23.9892501Z ##[command]git -c http.https://MainCo@dev.azure.com.extraheader="AUTHORIZATION: bearer ***" submodule update --init --force
2020-10-20T13:21:24.0147532Z Submodule 'DBPkg' (https://MainCo@dev.azure.com/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://MainCo@dev.azure.com/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://MainCo@dev.azure.com/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
更新2
管道可以访问授权项目中的任何 Azure DevOps 存储库,如之前的将作业授权范围限制为当前项目部分所述,除非将作业授权范围限制为引用的 Azure DevOps 存储库 启用.
启用此选项后,您可以将所有管道的访问范围缩小到仅由使用该存储库的管道作业中的结帐步骤明确引用的 Azure DevOps 存储库。
尝试关闭此选项并再次检查。
如果还是不行,你需要检查repo的安全性。找到您的 [项目名称] 构建服务帐户和项目集合构建服务帐户,确保它们都有足够的权限访问您的两个 git 存储库。
更新
尝试在 .gitmodules 中使用它,因为子模块 repo 与父模块在同一个 url 中。 :
[submodule "DBPkg"]
path = DBPkg
url = ../DBPkg
你也可以检查这个link:
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:
Contained in the same project, GitHub organization, or Bitbucket
Cloud account as the Git repo specified above.
Added by using a URL relative to the main repository. For example, this one would be checked out: git submodule add /../../submodule.git mymodule
This one would not be checked out: git submodule add https://dev.azure.com/fabrikamfiber/_git/ConsoleApp mymodule
您还可以查看 Azure DevOps 文档 here。
类似的博客供您参考:Using Git submodules in (private) Azure DevOps repositories
如果您没有更改“将作业授权范围限制为引用的 Azure DevOps 存储库”的权限,为子模块存储库添加一个检查步骤允许我授予它权限,并且子模块工作。不过它会下载存储库两次。
- checkout: git://project/RepositoryReferencedByTheSubmodule
- checkout: self
submodules: true
URL不需要匹配,子模块可以指向类似https://xxx@dev.azure.com/xxx/_git/RepositoryReferencedByTheSubmodule
在我们的 Git 项目中,我们在 .gitmodules
中定义了以下内容[submodule "DBPkg"]
path = DBPkg
url = https://MainCo@dev.azure.com/MainCo/OurProject/_git/DBPkg
构建 Azure Pipeline 时,在我的“获取源”管道步骤中(我使用的是“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://MainCo@dev.azure.com.extraheader="AUTHORIZATION: bearer ***" submodule update --init --force
2020-10-16T20:29:44.9923206Z Submodule 'DBPkg' (https://MainCo@dev.azure.com/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://MainCo@dev.azure.com/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://MainCo@dev.azure.com/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 部分剪切和粘贴。
编辑:从门户复制的问题中的回购 URL 是
https://MainCo@dev.azure.com/MainCo/OurProject/_git/MainAPIs
https://MainCo@dev.azure.com/MainCo/OurProject/_git/DBPkg
所以子模块位于 https://MainCo@dev.azure.com/MainCo/OurProject/_git/DBPkg 但不确定如何用 Git 子模块来表达上述内容。
编辑 2:
针对给出的答案,这里是代理报告的错误输出...
...
2020-10-20T13:21:23.9543308Z ##[command]git submodule sync
2020-10-20T13:21:23.9892501Z ##[command]git -c http.https://MainCo@dev.azure.com.extraheader="AUTHORIZATION: bearer ***" submodule update --init --force
2020-10-20T13:21:24.0147532Z Submodule 'DBPkg' (https://MainCo@dev.azure.com/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://MainCo@dev.azure.com/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://MainCo@dev.azure.com/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
更新2
管道可以访问授权项目中的任何 Azure DevOps 存储库,如之前的将作业授权范围限制为当前项目部分所述,除非将作业授权范围限制为引用的 Azure DevOps 存储库 启用.
启用此选项后,您可以将所有管道的访问范围缩小到仅由使用该存储库的管道作业中的结帐步骤明确引用的 Azure DevOps 存储库。
尝试关闭此选项并再次检查。
如果还是不行,你需要检查repo的安全性。找到您的 [项目名称] 构建服务帐户和项目集合构建服务帐户,确保它们都有足够的权限访问您的两个 git 存储库。
更新
尝试在 .gitmodules 中使用它,因为子模块 repo 与父模块在同一个 url 中。 :
[submodule "DBPkg"]
path = DBPkg
url = ../DBPkg
你也可以检查这个link:
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:
Contained in the same project, GitHub organization, or Bitbucket Cloud account as the Git repo specified above.
Added by using a URL relative to the main repository. For example, this one would be checked out:
git submodule add /../../submodule.git mymodule
This one would not be checked out:git submodule add https://dev.azure.com/fabrikamfiber/_git/ConsoleApp mymodule
您还可以查看 Azure DevOps 文档 here。
类似的博客供您参考:Using Git submodules in (private) Azure DevOps repositories
如果您没有更改“将作业授权范围限制为引用的 Azure DevOps 存储库”的权限,为子模块存储库添加一个检查步骤允许我授予它权限,并且子模块工作。不过它会下载存储库两次。
- checkout: git://project/RepositoryReferencedByTheSubmodule
- checkout: self
submodules: true
URL不需要匹配,子模块可以指向类似https://xxx@dev.azure.com/xxx/_git/RepositoryReferencedByTheSubmodule