Search code examples
gitlabcontinuous-integrationgit-submodules

Using Gitlab CI from a submodule


I'm trying to "mutualize" my CI.

I have a lot of project that use basically the same gitlab-ci.yml.

I was thinking about creating a git submodule containing the gitlab-ci.yml that all my project are using, in which I could inject env variable in order to make it generic so I could re-use it in my futur projects.

My problem is that I don't see any documentation about this so I was wondering :

  • Is it possible ? And if yes, how can I tell gitlab to use the gitlab-ci.yml that is inside of this submodule ?

  • If it's a bad idea, do you have any idea of the correct way to do this ?

Thanks !


Solution

  • What you're looking for are Gitlab CI template files, that can be include'd in other .gitlab-ci.yml files.

    You can check out the documentation for include here.

    Example :

    # .gitlab.ci.yml
    
    include:
      - 'https://gitlab.com/awesome-project/raw/main/.before-script-template.yml'
      - '/templates/.after-script-template.yml'
    

    This includes CI files with default variables, stages, workflows that can be overriden anywhere in your other CI files. This brings the genericity you need.