首页 > 解决方案 > 为什么 Gitlab CI 无法获取 git 子模块但在随后的推送中检查出子模块?

问题描述

我的项目由一个父项目和一个子项目组成。子项目作为子模块包含在父项目中。

我正在使用 Gitlab CI。下面是 .gitlab-ci.yml 文件。

stages:
 - build

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  
build-backend:
  image: mcr.microsoft.com/dotnet/core/sdk:3.1
  stage: build
  script:
    - echo "build-backend"
    - apt update -y
    - apt install -y nodejs npm
    - node --version
    - npm --version
    - ls -al MyApp/client
    - dotnet publish MyApp /p:PublishProfile="Profile"

gitmodules 文件看起来像这样

[submodule "MyApp/client"]
    path = MyApp/client
    url = ../myappclient.git
    branch = master

  

如果我对源代码进行更改并推送到 Gitlab,那么 Gitlab 会失败并出现此错误

fatal: destination path '/builds/def/abc/xyz/MyApp/client' already exists and is not an empty directory.

完整的错误信息

Running with gitlab-runner 13.1.0 (6214287e)
  on runner-docker-builder-7.dev.nsynd.com spMNyspT
Preparing the "docker" executor
00:00
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:052ed32b57d8892af69eb4141a96032b01534ccc63db136c5649813e727c78ca for mcr.microsoft.com/dotnet/core/sdk:3.1 ...
Preparing environment
00:02
Running on runner-spmnyspt-project-440-concurrent-0 via runner-docker-builder-7.dev.nsynd.com...
Getting source from Git repository
00:04
Fetching changes...
Reinitialized existing Git repository in /builds/def/abc/xyz/.git/
Checking out b626802d as MyBranch...
Updating/initializing submodules recursively...
Synchronizing submodule url for 'MyApp/client'
fatal: destination path '/builds/def/abc/xyz/MyApp/client' already exists and is not an empty directory.
fatal: clone of 'https://gitlab-ci-token:[MASKED]@git.dfghj.com/def/abc/mysubmodule.git' into submodule path '/builds/def/abc/xyz/MyApp/client' failed
Failed to clone 'MyApp/client'. Retry scheduled
fatal: destination path '/builds/def/abc/xyz/MyApp/client' already exists and is not an empty directory.
fatal: clone of 'https://gitlab-ci-token:[MASKED]@git.dfghj.com/def/abc/mysubmodule.git' into submodule path '/builds/def/abc/xyz/MyApp/client' failed
Failed to clone 'MyApp/client' a second time, aborting
ERROR: Job failed: exit code 1

如果我推动另一个更改(任何人为的更改),那么构建工作。

  1. 为什么Gitlab第一次获取子模块失败?
  2. 我需要在最后一次构建后清理吗?

标签: gitgitlabgitlab-cigit-submodules

解决方案


推荐阅读