使用git子模块,VSTS git构建失败

时间:2016-08-03 20:02:30

标签: git azure-devops git-submodules

我在Visual Studio Team Services项目中有一个git repos A和B. B是A的子模块,在.gitmodules中有以下配置:

[submodule "my_submodule"]
    path = somefolder/my_submodule
    url = https://xxx.visualstudio.com/xxx/_git/B

如果我使用选项Repository / Checkout Submodules进行构建,则会出现以下错误:

Repository type=TfsGit
localPath=C:\a\1\s
clean=False
sourceBranch=refs/heads/submoduletest
sourceVersion=0378dd86db31e4d7bff8de86a482b3d8e72dd3ba
Syncing repository: A (Git)
repository url=https://xxx.visualstudio.com/_git/A
checkoutSubmodules=True
Starting clone
Checking out 0378dd86db31e4d7bff8de86a482b3d8e72dd3ba to C:\a\1\s with submodules
Checked out branch refs/heads/submoduletest for repository A at commit 0378dd86db31e4d7bff8de86a482b3d8e72dd3ba
##[error]LibGit2Sharp.NotFoundException: Failed to resolve path 'C:/a/1/s/xxx/somefolder/my_submodule/.git': The system cannot find the path specified.
##[error]   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
##[error]   at LibGit2Sharp.SubmoduleCollection.Update(String name, SubmoduleUpdateOptions options)
##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.DoUpdateSubmodules(Repository repository, Int32 maxRecursionDepth, Int32 currentRecursionDepth, String username, String password, CancellationToken cancellationToken)
##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.UpdateSubmodules(ITaskEndpoint endpoint, Repository repository, Int32 maxRecursionDepth, CancellationToken cancellationToken)
##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncAndCheckout(Boolean cleanRepository, String sourceBranch, String sourceVersion, Boolean checkoutSubmodules, CancellationToken cancellationToken)
##[error]   at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.GitSourceProvider.<>c__DisplayClass3_0.<PrepareRepositoryAsync>b__0()
##[error]Microsoft.TeamFoundation.DistributedTask.Agent.Common.AgentExecutionTerminationException: Prepare repository failed with exception. ---> LibGit2Sharp.NotFoundException: Failed to resolve path 'C:/a/1/s/xxx/somefolder/my_submodule/.git': The system cannot find the path specified.
##[error]   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
##[error]   at LibGit2Sharp.SubmoduleCollection.Update(String name, SubmoduleUpdateOptions options)
##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.DoUpdateSubmodules(Repository repository, Int32 maxRecursionDepth, Int32 currentRecursionDepth, String username, String password, CancellationToken cancellationToken)
##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.UpdateSubmodules(ITaskEndpoint endpoint, Repository repository, Int32 maxRecursionDepth, CancellationToken cancellationToken)
##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncAndCheckout(Boolean cleanRepository, String sourceBranch, String sourceVersion, Boolean checkoutSubmodules, CancellationToken cancellationToken)
##[error]   at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.GitSourceProvider.<>c__DisplayClass3_0.<PrepareRepositoryAsync>b__0()
##[error]   --- End of inner exception stack trace ---
##[error]   at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.GitSourceProvider.<>c__DisplayClass3_0.<PrepareRepositoryAsync>b__0()
##[error]   at System.Threading.Tasks.Task.Execute()

有趣的错误消息似乎是:

LibGit2Sharp.NotFoundException: Failed to resolve path 'C:/a/1/s/xxx/somefolder/my_submodule/.git'

在我的机器上做一个git clone xxx / A --recursive。

梦幻般的文档指出了一个身份验证问题: https://www.visualstudio.com/en-us/docs/build/define/repository

但是这没有说明auth甚至在.gitmodules中使用相对路径也不会导致不同的错误消息。

有什么想法吗?

更新1

出于测试目的,我使用了一个分支。我将更改(添加子模块)合并到master并重试 - 现在出现以下错误:

##[error]LibGit2Sharp.NotFoundException: Object not found - no matching loose object (4fa408bc7b29e87b7032e0f78998516ff4a4da00)

该哈希是我子模块的HEAD - 显然可用。

2 个答案:

答案 0 :(得分:1)

@ eddie-msft对他的评论说得对:在master上有一个同名的文件夹。结帐到我的测试分支没有删除该文件夹。虽然这在我本地执行时有效,但VS Team Serivices似乎有问题。

但还有另一个问题:与文档相反,我要提供子模块的完整URL(https://xxx.visualstudio.com/xxx/_git/B)。文档说我应该使用相对URL(../B或../../B - 它是一个猜谜游戏),但这不起作用。

答案 1 :(得分:0)

.gitmodules文件存在一些问题。通常,文件中的路径应该是子模块存储库名称(方案中为“B”)。