【问题标题】:How to get gitlab-ci to checkout my submodule?如何让 gitlab-ci 检出我的子模块?
【发布时间】:2020-08-04 08:58:45
【问题描述】:

我正在尝试在 Gitlab CI 中配置自动构建。

我的项目有一个 git 子模块。

我正在使用 Linux docker 容器运行器。

Gitlab 无法检出子模块。

这是我的 .gitlab-ci.yml 文件。

stages:
 - build
 
variables:
  GIT_SUBMODULE_STRATEGY: recursive

build-backend:
  image: mcr.microsoft.com/dotnet/core/sdk:3.1
  stage: build
  script:
    - dotnet publish MyWebApp /p:PublishProfile="MyPublishProfile" /p:Password=1234
  artifacts:
    name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
    expire_in: 1 day
    paths:
      - MyWebApp/bin/Release

这里是 .gitmodules 文件

[submodule "MyWebApp/client"]
    path = MyWebApp/client
    url = git@git.mycompany.abc:company/client/myclient.git
    branch = qa

错误信息包含这一行

error: cannot run ssh: No such file or directory

gitlab 中的完整错误信息

Running with gitlab-runner 13.1.0 (6214287e)
  on runner-docker-builder-5.dev.nsynd.com t8cc1Yme
section_start:1596467453:prepare_executor
Preparing the "docker" executor
Using Docker executor with image mcr.microsoft.com/dotnet/core/sdk:3.1 ...
Pulling docker image mcr.microsoft.com/dotnet/core/sdk:3.1 ...
Using docker image sha256:abc123 for mcr.microsoft.com/dotnet/core/sdk:3.1 ...
section_end:1596467453:prepare_executor
section_start:1596467453:prepare_script
Preparing environment
Running on runner-t8cc1yme-project-440-concurrent-0 via runner-docker-builder-5.dev.nsynd.com...
section_end:1596467456:prepare_script
section_start:1596467456:get_sources
Getting source from Git repository
Fetching changes...
Reinitialized existing Git repository in /builds/company/client/MyWebApp/.git/
Checking out 0a9dd30c as qa...
Updating/initializing submodules recursively...
Synchronizing submodule url for 'MyWebApp/client'
Cloning into '/builds/company/client/MyWebApp/client'...
error: cannot run ssh: No such file or directory
fatal: unable to fork
fatal: clone of 'git@git.mycompany.abc:company/client/myclient.git' into submodule path '/builds/company/client/MyWebApp/client' failed
Failed to clone 'MyWebApp/client'. Retry scheduled
Cloning into '/builds/company/client/MyWebApp/client'...
error: cannot run ssh: No such file or directory
fatal: unable to fork
fatal: clone of 'git@git.mycompany.abc:company/client/myclient.git' into submodule path '/builds/company/client/MyWebApp/client' failed
Failed to clone 'MyWebApp/client' a second time, aborting
section_end:1596467459:get_sources
ERROR: Job failed: exit code 1

在父项目 (MyWebApp) 和子模块 (MyWebApp/client) 中,我都没有配置部署密钥和部署令牌。

【问题讨论】:

标签: git continuous-integration gitlab gitlab-ci


【解决方案1】:

Git 克隆不会自动克隆子模块。你需要明确的Git init and update 来引入子模块代码。

git clone https://github.com/cameronmcnz/surface.git
git submodule init
git submodule update

我不确定您是否可以将其用于 GitLab 的 YAML 文件中。

子模块版本

请注意,Git init and update 不会为您提供子模块的最新代码,但您将获得映射到父 Git 存储库提交的子模块的版本/提交。

【讨论】:

  • 你可以在下面使用最新的提交更新子模块:git submodule update --remote --recursive 添加 --recursive 以防你有多个子模块。
猜你喜欢
  • 1970-01-01
  • 2018-02-21
  • 1970-01-01
  • 2017-01-31
  • 2019-08-29
  • 2020-05-26
  • 1970-01-01
  • 2022-10-04
  • 1970-01-01
相关资源
最近更新 更多