Azure DevOps 构建中出现“在 .gitmodules 中找不到子模块路径的 url”错误

hcd*_*ocs 7 git azure azure-pipelines

存储库(“网站”)有一个子模块(“模板”)。该子模块在存储库的目录中被引用。目标是使用 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 文档。这是因为我不清楚同一项目的子模块是否可以在不提供显式凭据的情况下包含在存储库中。

  1. 通过用户界面:

    • “清理选项”:“所有构建目录”
    • “签出子模块”:True
    • 分支包含 .gitmodule 文件:True
  2. 通过 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
Run Code Online (Sandbox Code Playgroud)

git -c http.https://dev.azure.com/organization/project/_git/template.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)
  • 未成功测试的构建在没有 .gitmodules 文件的分支和具有 .gitmodules 文件的分支上进行。
  • 在 Bash 和(稍作调整)PowerShell 中测试构建任务均未成功。
  • 未能成功测试 Azure DevOps 存储库 URL 的各种结构(例如https://organization.visualstudio.com/project/_git/repohttps://$(PAT)@organization.com.visualstudio.com:/project/_git/template等)。

尝试的其他事情是上述内容的变体,包括git submodule add在命令之前的 PowerShell 任务中submodule update,在 Bash 任务中运行ls -lR以调查子模块文件是否已下载(构建任务有时会指示成功,即使文件丢失),以及.gitmodules 文件。

正如 .gitmodules 现在的情况(不成功):

[submodule "template"]
    path = <repo directory AKA "website">/<submodule directory AKA "template">
    url = https://dev.azure.com/organization/project/_git/template
Run Code Online (Sandbox Code Playgroud)

变化包括:

  • [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

...以及更多加上所有各种组合。没有一个是成功的。

我真的被困住了,很欣赏任何见解。谢谢。

and*_*ndy 13

不确定这是否有帮助,但对于重新定位的子模块(从存储库中的 /my-submodule 移动到 /src/my-submodule ),我一直在努力解决相同的错误。执行git rm --force /my-submodule、提交并推送到远程为我解决了这个问题。

我发现使用git submodule status有助于在本地检查子模块状态是否正确。在我尝试后,git rm它停止报告错误“致命:在 .gitmodules 中找不到子模块路径‘my-submodule’的 url”