GitLab Blog

How to automate the creation of GitLab Runners

thumbnail

To automate the creation of GitLab Runners, follow these steps:

  1. Retrieve a registration token:

    • If you need a token for the entire GitLab instance, go to Admin Area > Runners and click on "Set up a shared Runner manually". Then, copy the registration token provided.
    • For a specific group or project, navigate to the respective page and create a token under Settings > CI/CD > Runners.
  2. Use the access token to create a runner:

    • With the registration token, you can create a runner programmatically using GitLab's API or command-line tool.
    • Save the access token as it will only be displayed once.
  3. Reuse the runner token for multiple runners:

    • With the new runner creation method, you can reuse the runner token to register multiple runners.
    • Grouping runners with the same token provides a better overview in the Runners list.
  4. Automation of runner installation and registration:

    • If hosting the runner on a public cloud virtual machine, use infrastructure-as-code tools like Terraform to automate the installation process.
    • For example, you can use Terraform to install the runner application on a virtual machine hosted on Google Cloud Compute Engine.

To summarize:

  • Use the API or command-line tool to create a runner token and configuration.
  • Reuse the runner token to register multiple runners and achieve better fleet management.
  • Automate the runner installation and registration process using infrastructure-as-code tools like Terraform.