Can I use git submodules to store include templates for my .gitlab-ci.yml?

I have a bunch of repos that repeat very similar (or the same) snippets of code for my .gitlab-ci.yml files. Would it be possible to create templates in a yml file that live in a separate repo that’s added as a submodule, and then are included ( into each of my repos, and are able to be automatically updated by selecting the appropriate GIT_SUBMODULE_STRATEGY option?

I found my answer here:

And it’s no.

I’m doing that, it works fine. Running the git module update command in before script though

@splisson-altair Do you mind adding a snippet for illustration?

I’ve tried the following to no avail:

  - git submodule update --init --recursive path/to/mysubmodule

  - local: '/path/to/mysubmodule/file.yml'

GitLab indicates “Local file ‘/path/to/mysubmodule/file.yml’ does not exist!”.

1 Like

I’ve learned more from experience since my post. Th git submodule in the before_script does not help because the includes happen before (to build the final code I suppose). The GIT_SUBMODULE_STATEGY ( is the one useful to put in recursive. Also in a local copy of your repository, running git submodule update --remote, updates the current submodule commit that your project is tracking, that helped getting the right version.

It appears the capability is an open issue: