在 GitLab 管道中克隆子模块时出现’无法读取用户名’错误。

huangapple go评论73阅读模式
英文:

Getting 'could not read Username' error in GitLab pipeline when cloning a submodule

问题

我正在尝试在GitLab中为一个包含Git子模块的项目创建构建流水线。当流水线构建作业运行时,它尝试克隆子模块,但失败并显示以下错误信息:could not read Username for 'https://gitlab.com': No such device or address

Git子模块位于相同的GitLab组和相同的实例中。我已经像这样在.gitlab-ci.yml中添加了这些环境变量:

---
stages:
  - lint
  - build
  - deploy

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  GIT_SUBMODULE_FORCE_HTTPS: "true"

这是项目中的.gitmodules文件,我正在运行流水线的项目中:

[submodule "build-tools"]
        path = build-tools
        url = https://gitlab.com/core/frontend-dev/build-tools.git

这是项目的URL:https://gitlab.com/core/frontend-dev/api-service.git

因为它们都位于相同的GitLab实例中,我是否需要将子模块的URL转换为相对URL?

英文:

I'm trying to create a build pipeline in GitLab for a project that has a Git submodule included in the project's repository. When the pipeline build job runs it tries to clone the submodule but fails with this error: could not read Username for 'https://gitlab.com': No such device or address

The Git submodule lives in the same GitLab group on the same instance. I already added these environmental variables to the .gitlab-ci.yml like this:

---
stages:
  - lint
  - build
  - deploy

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  GIT_SUBMODULE_FORCE_HTTPS: "true"

Here's the .gitmodules file in the project where I'm running the pipeline:

[submodule "build-tools"]
        path = build-tools
        url = https://gitlab.com/core/frontend-dev/build-tools.git

This is the project's url: https://gitlab.com/core/frontend-dev/api-service.git

Do I need to convert the submodule url to a relative url since they are both in the same GitLab instance?

答案1

得分: 1

我解决了这个问题。解决方案分为两部分。

首先,你需要将.gitmodules中的url更改为相对路径,像这样:

[submodule "build-tools"]
path = build-tools
url = ../build-tools.git

这个url是相对于存储.gitmodule的项目的路径的。所以如果子模块和项目在同一个组中,路径将是../

第二部分是你需要给项目流水线赋予权限访问子模块项目。进入被用作子模块的项目设置,并找到“Token Access”。它在“设置->CI/CD->Token Access”中。将项目的路径添加到“允许以下项目的CI作业令牌访问此项目”。

英文:

I solved the issue. The solution is two parts.

First you have to change the url in the .gitmodules to be relative like this:

[submodule "build-tools"]
        path = build-tools
        url = ../build-tools.git

The url is relative to the project where you are storing the .gitmodule. So if the submodule and the project are in the same group then the path would be ../

The second part is you have to give permission to the project pipeline to access the submodule project. Go into the project settings that is being used as the submodule and find 'Token Access'. It's in 'Settings->CI/CD->Token Access'. Add the path to the project under 'Allow CI job tokens from the following projects to access this project'.

huangapple
  • 本文由 发表于 2023年7月18日 00:24:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706408.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定