克隆子模块时,GitLab 管道中出现“无法读取用户名”错误

问题描述 投票:0回答:2

我正在尝试在 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

这是项目的网址:

https://gitlab.com/core/frontend-dev/api-service.git

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

gitlab gitlab-ci-runner
2个回答
7
投票

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

首先你必须将 .gitmodules 中的 url 更改为相对的,如下所示:

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

该 url 与您存储 .gitmodule 的项目相关。因此,如果子模块和项目位于同一组中,那么路径将是

../

第二部分是您必须授予项目管道访问子模块项目的权限。进入用作子模块的项目设置并找到“令牌访问”。它位于“设置->CI/CD->令牌访问”中。在“允许以下项目中的 CI 作业令牌访问此项目”下添加项目的路径。


0
投票

我已经通过添加到 CI 解决了这个错误:

variables:
    GIT_SUBMODULE_STRATEGY: none
  before_script:
    - git -c "url.https://gitlab-ci-token:${CI_JOB_TOKEN}@git.elewise.com/.insteadOf=https://gitlab.com/" submodule update --init --recursive
© www.soinside.com 2019 - 2024. All rights reserved.