【问题标题】:Using relative url for git submodule needs credentials使用 git 子模块的相对 url 需要凭据
【发布时间】:2016-08-04 09:50:34
【问题描述】:

Team Services 文档 (https://www.visualstudio.com/en-us/docs/build/define/repository#what-kinds-of-submodules-can-i-check-out) 指出我可以执行 $ git add submodule if

  • 它是一个直接子模块
  • 未经身份验证(不适用)
  • 已通过身份验证
    • 包含在同一个团队项目中
    • 使用主存储库中的相对 url 添加

他们举了一个例子:

git submodule add /../../submodule.git mymodule

如果我在同一个项目中引用一个 git repo,比如

git submodule add ./../other-repo mymodule

它解析了正确的 repo,但希望我提供凭据。构建失败并显示以下消息:

Cloning into 'mymodule'...
fatal: could not read Username for 'https://xxx.visualstudio.com': Invalid argument

提供带有凭据 (https://user:password@xxx.visualstudio.com/...) 的完整 URL 是可行的,但 IMO 是一个糟糕的解决方案。

文档建议这应该使用相对 url 而无需凭据。我错了吗?

编辑 1:

使用 system.debug 运行:true

Entering OnPrepareEnvironment
Primary repository: xxx
Calculating build folder hash key.
Loading tracking config if exists: C:\a\SourceRootMapping\07a8b96d-d805-4646-83d3-e7b2fbe394c2\18\SourceFolder.json
Creating new tracking config.
Loading top-level tracking config if exists: C:\a\SourceRootMapping\Mappings.json
Writing config to file: C:\a\SourceRootMapping\Mappings.json
Writing config to file: C:\a\SourceRootMapping\07a8b96d-d805-4646-83d3-e7b2fbe394c2\18\SourceFolder.json
Checking if artifacts directory exists: C:\a\1\a
Creating artifacts directory.
Checking if test results directory exists: C:\a\1\TestResults
Creating test results directory.
Creating binaries directory.
Setting local variables.
Create the initial timeline records for the tasks
Preparing repositories
repo clean = False
Found 3 endpoints to consider
Found 1 repositories to sync
Starting: Get sources
build.fetchtags=false
Entering GitSourceProvider.PrepareRepositoryAsync
Repository type=TfsGit
localPath=C:\a\1\s
clean=False
sourceBranch=refs/heads/r_080
sourceVersion=26d5a7a6e6ed47c8f12ee5dc5b376d6731b7863a
Syncing repository: xxx (Git)
repository url=https://xxx.visualstudio.com/_git/xxx
checkoutSubmodules=False
Starting clone
Checking out 26d5a7a6e6ed47c8f12ee5dc5b376d6731b7863a to C:\a\1\s
Checked out branch refs/heads/r_080 for repository xxx at commit 26d5a7a6e6ed47c8f12ee5dc5b376d6731b7863a
Leaving GitSourceProvider.PrepareRepositoryAsync
Leaving OnPrepareEnvironment
Running tasks
Starting task: Run git
##[warning]File name doesn't indicate a full path to a executable file.
Executing the following command-line. (workingFolder = C:\a\1\s)
git submodule add ./../other_repo mymodule
Error message highlight pattern: 
Warning message highlight pattern: 
C:\Windows\system32\cmd.exe /c "git submodule add ./../other_repo mymodule"
Cloning into 'mymodule'...
Fatal: InvalidOperationException encountered.
bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for 'https://xxx.visualstudio.com': Invalid argument
fatal: clone of 'https://xxx.visualstudio.com/_git/other_repo' into submodule path 'mymodule' failed
Finishing task: CmdLine
##[error]System.Exception: Task CmdLine failed. This caused the job to fail. Look at the logs for the task for more details.
##[error]   at Microsoft.TeamFoundation.DistributedTask.Worker.JobRunner.Run(IJobContext jobContext, IJobRequest job, IJobExtension jobExtension, CancellationTokenSource tokenSource)
Entering OnFinalizeJob
Leaving OnFinalizeJob


编辑 2:

我无法回答这个问题。文档有误/不清楚,我选择检查子模块,如 @eddie-msft 所说 - 但请注意:VSTS git build fails with git submodule

【问题讨论】:

  • 我尝试使用命令添加 Git 子模块并将构建排队,但没有发现任何问题。您可以将“system.debug”变量设置为“true”的构建排队,然后共享整个日志吗?
  • @Eddie-MSFT 添加为编辑
  • 根据日志,您正在通过“命令行”构建任务在构建过程中添加子模块存储库。您可以尝试在本地计算机上添加子模块然后推送更改吗?也请尝试使用“git submodule add ../other-repo mymodule”命令。
  • 我在本地添加它并尝试在构建步骤中“git submodule update --init”,但什么也没做。使用 ../other-repo mymodule 失败并显示相同的错误消息。
  • 您不需要在构建步骤中直接获取它,只需在构建定义存储库设置中选中“checkout submodule”选项即可。

标签: git azure-devops git-submodules azure-pipelines


【解决方案1】:

我从Submodules - Azure Repos 了解到,在以下情况下存在问题:

如果您按照上面部分的说明限制了作业访问令牌,那么您将无法执行此操作。

我自己只尝试了 nr 1,它对我们有用。

解决方法 1:用于 DevOps 中的子模块 repo

解决方法 2:如果需要不同的凭据

解决方法 3:自定义脚本以重用访问令牌以进行子模块同步

https://stackoverflow.com/a/63593883/134761

steps:
- checkout: self
  submodules: false
  persistCredentials : true

- powershell: |
    $header = "AUTHORIZATION: bearer $(System.AccessToken)"
    git -c http.extraheader="$header" submodule sync
    git -c http.extraheader="$header" submodule update --init --force --depth=1

【讨论】:

  • 使用相对路径为我的天蓝色管道修复了它!谢谢
  • 解决方法 3 立即为我工作,谢谢!
【解决方案2】:

还请检查您的两个存储库的路径。如果您的项目中只有两个存储库,则第一个创建的存储库 A 的路径为:

https://xxxx.visualstudio.com/_git/A

第二个创建的 repo B 的路径是:

https://xxxx.visualstudio.com/A/_git/B

在这种情况下,您需要使用如下相对路径:

../../A/_git/B

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 2017-08-09
    • 2015-10-25
    • 1970-01-01
    • 2022-10-19
    • 2023-04-03
    • 1970-01-01
    相关资源
    最近更新 更多