Cannot fetch submodules
There is no way to tell the CI runner to do a recursive clone (git clone --recursive
) and fetch submodules. The .gitlab-ci.yml
file should allow projects to enable getting submodules when the clone/fetch is performed. The workaround of forcing projects to separately configure SSH and Git and initialize submodules in the CI jobs is unsatisfactory -- the submodules should be checked out at the same time as the rest of the Git project.
Currently, recursive checkout is hard coded to be disabled in abstract.go and there is no way to change it.
Why is recursive clone disabled?
What is the reason that recursive clone is disabled? If a problem contains submodules, wouldn't the submodules be needed in order to build the project? Shouldn't submodules be fetched by default? There may be special cases where a script needs to modify the Git submodule URLs or something, but that is a rare case and that should be where special workarounds could be applied, no in the usual case where submodules are simply cloned in the normal way.
Workaround?
Jobs in .gitlab-ci.yml
can perform git submodule update --init
in the job itself. The GitLab CI documentation describes the workaround in Using SSH keys.
However, there are serious problems with the workaround that make it entirely unsatisfactory, especially when other CI systems like Jenkins have built-in submodule support with no extra effort. Some of the problems with this workaround include
- Manual effort and duplicate copy-and-pasted code in every project's
.gitlab-ci.yml
- Poor performance for parallel builds since submodules must be cloned separately within each job
- Security risk since the private SSH key needs to be passed in to the project build scripts
- Requires the build image to have OpenSSH client and Git installed
Other references to the workaround:
- Stack Overflow answer describing GitLab CI SSH key/private repository access
- Someone was trying to implement this workaround and ran into problems in this GitLab forum post.
Possible fix
If it is desirable to have submodules left uninitialized by default, as is currently done, then we can provide an option in .gitlab-ci.yml
similar to the GIT_STRATEGY and GIT_DEPTH options in the variables:
section of the .gitlab-ci.yml
file.
New variable GIT_SUBMODULES
Add a new variable called GIT_SUBMODULES
. If it is set to init
, then submodules will be initialized in the same way as the Git commit git submodule update --init --recursive
.
Access protection
If the Git submodules exist on the same GitLab server as the project to which the CI job belongs, and the submodules have SSH URLs, the CI runner should use the same access level as the user that pushed the commit to GitLab. (Need to make sure that users who have commit rights to the superproject can't gain access to other projects which they could add as submodules, if they don't actually have rights to access those submodules.)