Submodule won't clone

This is my first time using a submodule in a GitLab CI/CD pipeline. And, so far, I’m failing.

I’ve read Using Git submodules with GitLab CI/CD | GitLab and think I’ve set it up correctly. I think maybe using CI_JOB_TOKEN to clone the submodule is the fix, but I’m having no luck finding the documentation on how to use the CI_JOB_TOKEN to clone a submodule. … But maybe I’m doing something else wrong?

Here’s the CI/CD log.

$ git submodule init
$ git submodule update
Cloning into '/builds/project-b/project-a'...
fatal: could not read Username for 'https://my-server.com': No such device or address
fatal: clone of 'https://my-server.com/project-a.git' into submodule '/builds/project-b/project-a' failed
Failed to clone 'project-a'. Retry scheduled
Cloning into '/builds/project-b/project-a'...
fatal: could not read Username for 'https://my-server.com': No such device or address
fatal: clone of 'https://my-server.com/project-a.git' into submodule '/builds/project-b/project-a' failed
Failed to clone 'project-a' second time, aborting
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1

GitLab is self hosted on an LAN server using HTTPS.
https://my-server.com

My projects are next to each other in GitLab, under my-group for common access privileges.

my-group
   project-a
   project-b

The project-a has a python script I want to use in project-b.

project-a/
  stuff.py

The project-b has project-a as a submodule.

project-b/
  .gitlab-ci.yml
  .gitmodules
  project-a

The project-b CI/CD does more but I’ve only included the submodule part here. My .gitlab-ci.yml

stages:
  - build

do-build
  stage: build
  script:
    - git submodule init
	- git submodule update

My .gitmodules

[submodule “project-b”]
   path = project-b 
   url = ../project-b.git

Example users: bob is a developer; ci-robot is just so we can get an access token not belonging to a human. Users in my-group

  • bob with developer privileges for project-a and project-b
  • ci-robot with developer privileges like bob but also with an access token

In the past, I got stuff.py with wget and ci-robot’s token. This worked but I want to use a submodule. Just for reference…

script:
  - "wget -O stuff --header='PRIVATE-TOKEN: xhSijU78blahBlahBlah' --no-check-certificate 'https://my-server.com/api/v4/projects/23/repository/files/stuff.py/raw?ref=master'"

Have you tried adding the environment variable to get the submodules?

We have projects that have submodules and all we do is add

variables:
    GIT_SUBMODULE_STRATEGY: recursive

To our CI, no need to then use any of the git submodule init or git submodule update stuff…

2 Likes

@jedihomer Thanks! That works :+1:
Silly me read " You can set the GIT_SUBMODULE_STRATEGY variable to…" to mean it was optional.