存储库(“网站”)有一个子模块(“模板”)。该子模块在存储库的目录中被引用。目标是使用 Azure DevOps 管道一起构建存储库和子模块。但是,Azure DevOps 构建会引发以下错误:
fatal: No url found for submodule path '<repo directory AKA "website">/<submodule directory AKA "template">' in .gitmodules
[error]Git submodule update failed with exit code: 128
根据调整情况.gitmodule
文件,也会抛出此错误:
-
fatal: no submodule mapping found in .gitmodules for path '<repo directory AKA "website">/<submodule directory AKA "template">'
.
这个问题与 Stack Overflow 上提出的其他问题类似,但不同之处在于 Azure DevOps 构建中的默认初始步骤是签出分支中的文件。所以脚本(比如git rm --cached <pathtomodule>
) 不能先运行。
“网站”和“模板”存储库位于同一个 Azure DevOps 项目中。
我尝试了两种方法都没有成功。两者均基于 Microsoft 文档。这是因为我不清楚同一项目的子模块是否可以在不提供显式凭据的情况下包含在存储库中。
-
通过用户界面:
- “清理选项”:“所有构建目录”
- “签出子模块”:True
- 分支包含 .gitmodule 文件:True
通过 PowerShell 任务中的 git 命令:
尝试了两者的变体:
$AUTH=$(echo -n ":$(PAT)" | openssl base64 | tr -d '\n')
git -c http.https://dev.azure.com/organization/project/_git/template.extraheader="AUTHORIZATION: basic $AUTH" clone https://dev.azure.com/organization/project/_git/template --no-checkout --branch master
and
git -c http.https://dev.azure.com/organization/project/_git/template.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" submodule update --init --recursive
- 未成功测试的构建在没有 .gitmodules 文件的分支和具有 .gitmodules 文件的分支上进行。
- 在 Bash 和(稍作调整)PowerShell 中测试构建任务均未成功。
- 未能成功测试 Azure DevOps 存储库 URL 的各种结构(例如
https://organization.visualstudio.com/project/_git/repo
, https://$(PAT)@organization.com.visualstudio.com:/project/_git/template
, etc.).
尝试过的其他事情是上述内容的变体,包括git submodule add
在 PowerShell 任务之前submodule update
命令,运行ls -lR
在 Bash 任务中调查是否下载了子模块文件(即使文件丢失,构建任务有时也会指示成功)以及 .gitmodules 文件的无穷变化。
正如 .gitmodules 现在的样子(不成功):
[submodule "template"]
path = <repo directory AKA "website">/<submodule directory AKA "template">
url = https://dev.azure.com/organization/project/_git/template
变化包括:
[submodule "<repo directory AKA 'website'>/template"]
path = D:\\a\\1\\s\\<repo directory AKA "website">\\<submodule directory AKA "template">
path = $env:Build.SourcesDirectory/template
url = ../project/_git/template
...以及更多加上所有各种组合。没有一个是成功的。
我真的被困住了,很欣赏任何见解。谢谢。