How can I use submodules when running gitlab-runner locally?

Viewed 1022

On our Gitlab server I have two repos, where one repo ('EPSILON-SDK-C') is a submodule in the other. When I run gitlab-runner locally on my developer machine

 sudo gitlab-runner exec docker build_fw

gitlab-runner can't find the submodule, as seen in this ouput from gitlab-runner:

Updating/initializing submodules...
Submodule 'thirdparty/EPSILON-SDK-C' (/home/me/gitlab_repos/EPSILON-SDK-C) registered for path 'thirdparty/EPSILON-SDK-C'
fatal: repository '/home/me/gitlab_repos/EPSILON-SDK-C' does not exist
fatal: clone of '/home/me/gitlab_repos/EPSILON-SDK-C' into submodule path '/builds/0/project-0/thirdparty/EPSILON-SDK-C' failed
Failed to clone 'thirdparty/EPSILON-SDK-C'. Retry scheduled
fatal: repository '/home/me/gitlab_repos/EPSILON-SDK-C' does not exist
fatal: clone of '/home/me/gitlab_repos/EPSILON-SDK-C' into submodule path '/builds/0/project-0/thirdparty/EPSILON-SDK-C' failed
Failed to clone 'thirdparty/EPSILON-SDK-C' a second time, aborting
ERROR: Job failed: exit code 1
FATAL: exit code 1

However, when our Gitlab server is triggered by a commit, Gitlab successfully builds a binary using the submodule, as seen in this Gitlab pipeline output (4-5 lines removed for clarity):

Updating/initializing submodules...
Synchronizing submodule url for 'thirdparty/EPSILON-SDK-C'
Entering 'thirdparty/EPSILON-SDK-C'
   (4-5 lines here removed for readabilty)
Authenticating with credentials from job payload (GitLab Registry)

Question: Gitlab has no problems locating the submodule, so why can't the local gitlab-runner find the submodule?

My .gitlab-ci.yml looks like this:

image: "gitlab.company.local:4567/me/dockerforfw:latest"

stages:
  - build

build_fw:
  stage: build

  variables:
    GIT_SUBMODULE_STRATEGY: normal

  script:
    - "bash bin/dorelease_linux.sh"

My .gitmodules looks like this:

$ cat .gitmodules
[submodule "thirdparty/EPSILON-SDK-C"]
    path = thirdparty/EPSILON-SDK-C
    url = ../EPSILON-SDK-C

Note that the submodule URL is relative, as required by the Gitlab documentations: https://docs.gitlab.com/ee/ci/git_submodules.html#configuring-the-gitmodules-file

I do have access to the submodule repo, so I don't this issue is related to permissions:

$ git submodule sync
Synchronizing submodule url for 'thirdparty/EPSILON-SDK-C'

My local gitlab-runner is version 12.3.0 (a8a019e0), and our Gitlab server is version GitLab Enterprise Edition 12.3.4-ee.

Things I have tried:

I have tried with ab absolute URL for the submodule. I've also tried keeping a local clone of the submodule repo in /home/me/gitlab_repos/ I also tried adding these before_script actions:

before_script:
  - git submodule sync --recursive
  - git submodule update --init --recursive

(UPDATE: I've edited my question for clarity)

1 Answers

I think I have some insight to this, as I am running into this right now.

On gitlab I have:

group1/proj1
group1/proj2

with this .gitsubmodules in proj1

[submodule "proj2"]
    path = proj2
    url = ../proj2.git

I tried running

> C:\code\proj1>gitlabrunner.exe  exec shell build_proj1 --shell powershell

but got

fatal: clone of 'c:\code/proj2.git' into submodule path 'C:/code/proj1/builds/0/project-0/proj2' failed
Failed to clone 'proj2'. Retry scheduled
Cloning into 'C:/code/proj1/builds/0/project-0/proj2'...
fatal: 'c:\code/proj2.git' does not appear to be a git repository
fatal: Could not read from remote repository.

I realized that:
1. I didn't have proj2 locally cloned
2. there was a trailing .git

So I made sure the repo actually exists locally

> cd c:\code
> git clone git@gitlab...com:group1/proj2.git
> cd proj2
> pwd
C:\code\proj2

AND

remove the '.git' suffix in .gitsubmodules

[submodule "proj2"]
    path = proj2
    url = ../proj2

And voila, now > C:\code\proj1>gitlabrunner.exe exec shell build_proj1 --shell powershell is able to properly find ..\proj2

Versions

> c:\code\proj1>C:\gitlab\gitlab-runner-windows-amd64.exe -v
Version:      12.6.0
Git revision: ac8e767a
Git branch:   12-6-stable
GO version:   go1.13.4
Built:        2019-12-22T11:55:34+0000
OS/Arch:      windows/amd64
Related