'Why does Gitlab CI fail to get git submodule but on subsequent push checks out the submodule?
My project consists of a parent project and a child project. The child project is included in the parent project as a submodule.
I am using Gitlab CI. Below is the .gitlab-ci.yml file.
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"
The gitmodules file looks like this
[submodule "MyApp/client"]
path = MyApp/client
url = ../myappclient.git
branch = master
If I make a change to the source code and push to Gitlab, then Gitlab fails with this error
fatal: destination path '/builds/def/abc/xyz/MyApp/client' already exists and is not an empty directory.
Complete error message
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
If I push another change (any contrived change), then the build works.
- Why does Gitlab fail to get the submodule the first time?
- Do I need to clean up after the last build?
Solution 1:[1]
Using ´git cloneinstead of
git fetchseems to be a workaround. You can set it in your CI settings or add the following parameter in your
.gitlab-ci.yml`:
variables:
GIT_STRATEGY: clone
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Günther Jena |