发布
社区首页 >问答首页 >为什么Gitlab CI不能获得git子模块,但是在随后的推出子模块时呢?

为什么Gitlab CI不能获得git子模块,但是在随后的推出子模块时呢?
EN

Stack Overflow用户
提问于 2020-08-06 12:45:00
回答 1查看 369关注 0票数 2

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

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

代码语言:javascript
代码运行次数:0
复制
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文件如下所示

代码语言:javascript
代码运行次数:0
复制
[submodule "MyApp/client"]
    path = MyApp/client
    url = ../myappclient.git
    branch = master

如果我更改了源代码并将其推送到Gitlab,那么Gitlab就会出现此错误。

代码语言:javascript
代码运行次数:0
复制
fatal: destination path '/builds/def/abc/xyz/MyApp/client' already exists and is not an empty directory.

完全错误信息

代码语言:javascript
代码运行次数:0
复制
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. 我需要在上次构建之后清理吗?
EN

回答 1

Stack Overflow用户

发布于 2022-04-25 07:58:44

使用git clone而不是git fetch似乎是一种解决办法。可以在CI设置中设置它,也可以在.gitlab-ci.yml中添加以下参数

代码语言:javascript
代码运行次数:0
复制
variables:
  GIT_STRATEGY: clone
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63283906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档