英文:
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'.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论