将 Gitlab 的 CI/CD 与子模块一起使用 - 无法运行 ssh

Net*_*nel 17 gitlab gitlab-ci

我有两个私有存储库:MyProject、MyProjetUtils。

我的项目使用 MyProjectUtils 作为子模块。

我的 .gitsubmodules 看起来像这样:

[submodule "MyProjetUtils"]
    path = MyProjetUtils
    url = git@gitlab.com:MyCompany/MyProjetUtils.git
Run Code Online (Sandbox Code Playgroud)

我的 .gitlab-ci.yml 文件如下所示:

default:
  image: python:latest
variables:
  GIT_SUBMODULE_STRATEGY: recursive
all_test:
  stage: test
  script:
    - apt-get update
    - pip install -r requirements.txt
    - python tests/run_tests.py
Run Code Online (Sandbox Code Playgroud)

我在作业运行期间遇到的错误:

Updating/initializing submodules recursively with git depth set to 50...
Submodule 'MyProjetUtils' (git@gitlab.com:MyCompany/MyProjetUtils.git) registered for path 'MyProjetUtils'
Cloning into '/builds/MyCompany/MyProject/MyProjetUtils'...
error: cannot run ssh: No such file or directory
fatal: unable to fork
fatal: clone of 'git@gitlab.com:MyCompany/MyProjetUtils.git' into submodule path '/builds/MyCompany/MyProject/MyProjetUtils' failed
Failed to clone 'MyProjetUtils'. Retry scheduled
Run Code Online (Sandbox Code Playgroud)

此错误发生在测试阶段之前。我在这里这里寻找答案,但找不到答案。

Rek*_*vni 27

您发布的第一个链接包含您正在寻找的解决方案:

当您的子模块位于同一 GitLab 服务器上时,您应该在 .gitmodules 文件中使用相对 URL。然后,您可以在所有 CI/CD 作业中使用 HTTPS 进行克隆。您还可以使用 SSH 进行所有本地结帐。

假设您的子模块位于同一组中,请更新您的子模块.gitmodules以使用相对 URL。

IE:

[submodule "MyProjetUtils"]
    path = MyProjetUtils
    url = ../../MyCompany/MyProjetUtils.git
Run Code Online (Sandbox Code Playgroud)

可能需要更新../../才能为您的小组工作。


dav*_*idA 6

除了@Rekovni的 答案之外,您可能还需要在子模块的项目配置中启用令牌访问:

Settings > CI/CD Settings > Token Access
Run Code Online (Sandbox Code Playgroud)

确保启用“允许使用 CI_JOB_TOKEN 访问此项目”,并将父项目的路径添加到“允许以下项目中的 CI 作业令牌访问此项目”下面的字段,然后单击“添加项目”。

这将确保您的父项目有权克隆子模块存储库。