Streamlining CI/CD with GitLab Multi Group Runner

Blake Bradford Avatar

·

Streamlining CI/CD with GitLab Multi Group Runner

Are you frustrated with GitLab’s lack of support for assigning a CI runner to multiple groups? Look no further than GitLab Multi Group Runner! This powerful tool provides a seamless workaround for this limitation, enabling you to streamline your CI/CD processes and enhance developer productivity. In this article, we will explore the installation, configuration, and usage of GitLab Multi Group Runner, empowering you to take full advantage of its capabilities.

Installation

GitLab Multi Group Runner can be installed as a standalone command line tool or as a custom GitLab runner. To install it as a command line tool, simply use pip on Python 3.5+:

python3 -m pip install gitlab-multi-group-runner

For Arch Linux users, an AUR package is also available:

yay -S python-gitlab-multi-group-runner

Alternatively, you can download pre-built executables from the releases page for 64-bit Linux distributions and macOS High Sierra or newer.

To install GitLab Multi Group Runner as a custom GitLab runner, follow these steps:

  1. Create a new GitLab repository to store the configuration file.
  2. Install GitLab runner on a dedicated host, referring to the GitLab runner documentation.
  3. Retrieve the registration token from the repository’s settings in GitLab.
  4. Register the GitLab runner with the command gitlab-runner register, providing the necessary information such as the GitLab instance URL, registration token, description, and executor.
  5. Clone the GitLab Multi Group Runner GitHub repository onto the runner host and run the installation command.
  6. Configure the config.toml file to specify the builds and cache directories, as well as the custom runner’s executable and arguments.
  7. Create a configuration file named multi-group-runner-config.yml in the configuration repository, detailing the groups, projects, and runner IDs to be assigned.
  8. Restart the GitLab runner service.
  9. Create a .gitlab-ci.yml file in the repository to trigger the CI pipeline and activate the custom runner.
  10. (Optional) Set up a scheduled event in GitLab to automatically configure new projects at regular intervals.

Configuration

GitLab Multi Group Runner relies on two configuration files: the local configuration file and the repository configuration file.

The local configuration file is located on the same machine as the GitLab Multi Group Runner executable. It contains parameters for GitLab API access and specifies runner and group/project configurations. For example:

general:
disable_shared_runners: true
gitlab:
auth_token: xxxxxxxxxxxxxxxxxxxx
url: https://mygitlab.com
runners:
- allowed_projects_rules:
one_member_of:
- my-group-name
- my-user-name
ids:
- 1
- 3
config_repo:
branch: master
path: administration/my-multi-group-runners

The repository configuration file, named multi-group-runner-config.yml, is located in the root of the configuration repository. It defines specific runner assignments for groups and projects. Here’s an example configuration:

runners:
- groups_and_projects:
- mygroup
- myusername/myproject
ids:
- 1
- 3

Usage

Using the Standalone Command Line Tool

To use GitLab Multi Group Runner as a standalone command line tool, execute the following command, specifying the local configuration file and the configuration repository path:

gitlab-multi-group-runner -f my_config.yml administration/my-multi-group-runners

GitLab Multi Group Runner will read both configuration files, validate the settings, and make the necessary API calls to add the assigned runners to the specified projects.

You can add the --all parameter to fetch all configuration repositories defined in the local config file.

Using GitLab Custom Runner

When using GitLab Multi Group Runner as a custom GitLab runner, simply push a new commit to the configuration repository. The CI pipeline will automatically trigger, applying the runner assignments and configuration specified in the repository.

Conclusion

GitLab Multi Group Runner offers a powerful solution for assigning CI runners to multiple groups in GitLab. By following the installation, configuration, and usage steps outlined in this article, you can leverage this tool to streamline your CI/CD processes and enhance collaboration among development teams. Embrace the power of GitLab Multi Group Runner and unlock productivity gains in your software development workflows.

Leave a Reply

Your email address will not be published. Required fields are marked *