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 (https://docs.gitlab.com/ee/ci/yaml/#include) 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: https://gitlab.com/gitlab-org/gitlab-ce/blame/master/doc/ci/yaml/README.md#L1670

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:

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

include:
  - 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 (https://docs.gitlab.com/ee/ci/git_submodules.html) 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: https://gitlab.com/gitlab-org/gitlab/issues/25249