DevOps by Patrik

Centralizing CI/CD Scripts Across Projects

Managing CI/CD scripts and configurations across multiple projects can quickly become a challenge. Repeating the same files and logic leads to maintenance overhead and inconsistency. This Snipp explores how to centralize your CI scripts and use them across different GitLab projects, using reliable and maintainable techniques.

This guide introduces three practical approaches:

  • Git submodules
  • GitLab includes
  • Downloading scripts at runtime

Each method suits different use cases, and this Snipp Set helps you choose the right one and implement it cleanly.

gitlab
ci-cd
automation
scripting
reuse
...see more

Using Git submodules is a clean way to share CI scripts between projects. You create a separate repository for your shared CI folder and link it as a submodule inside each project.

Steps:

  1. Move your shared CI files (scripts, configs, etc.) into a separate Git repo.

  2. In each project, add the submodule:

    git submodule add https://gitlab.com/your-group/ci-templates.git CI
  3. Commit the changes:
    git add .gitmodules CI
    git commit -m "Add CI submodule"
  4. Update submodules when cloning:
    git submodule update --init --recursive

Benefits:

  • Keeps scripts version-controlled and consistent
  • Easy to manage changes centrally

Use this when: You want full access to the CI folder and version control it tightly.

Comments