Setting Up GitLab CI Runners

·

Welcome to this friendly and informative guide on installing GitLab CI runners! If you're ready to boost your CI/CD pipelines with high-performance managed runners, you're in the right place. We'll walk you through each step to get your runners up and running smoothly.

Why use GitLab CI runners?

First, let's understand why GitLab CI runners are so essential. Runners are lightweight agents that execute your CI/CD jobs. While GitLab offers shared runners for public projects, using self-managed runners gives you control and customization for private projects. Here are some benefits:

  • Isolation and Customization: Tailor environments for consistency and reproducibility.
  • Scalability: Easily scale your CI/CD infrastructure by adding more self-managed runners.
  • Security: Maintain control by hosting runners within your infrastructure.

Prerequisites

Before we dive into the installation process, make sure you have the following:

  • A GitLab instance (self-managed or not)
  • A dedicated host machine for the runner
  • GitLab runner binary installed on the host machine

Step-by-step installation

Step 1: Create the runner

Head over to your GitLab repository settings and navigate to CI/CD, then expand the Runners section. Here, you can create a new runner. Assign tags to your runner to streamline it for specific jobs.

Step 2: Register the runner

On your runner machine, open the terminal with sudo permissions. Enter the registration URL and run the command gitlab-runner run. This will allow you to monitor the live status of the jobs assigned to and executed by the runner.

Step 3: Configure the runner

You can tweak the runner settings by modifying the /etc/gitlab-runner/config.toml file according to your requirements. Here's a basic example:

tomlCopier le code

[[runners]]
 name = "My Self-Managed Runner"
 url = "https://gitlab.com/"
 token = "your_registration_token"
 executor = "docker"
 [runners.custom_build_dir]
 [runners.docker]
   tls_verify = false
   image = "alpine:latest"
   privileged = true

Step 4: Start the runner

Finally, start your runner using the following commands:

bashCopier le code

sudo gitlab-runner start
sudo gitlab-runner run

Don't forget to restart the runner with sudo gitlab-runner restart if you make any changes to the config.toml file.

Setting up .gitlab-ci.yml

An essential part of this process is the .gitlab-ci.yml file. Pipelines get initiated every time this file is created, modified, committed, or pushed to the repo. Make sure the file name matches exactly as .gitlab-ci.yml to avoid any issues.

Create the file with the same tag or tags assigned to the runner to ensure the correct runner(s) handle the job/pipeline. Here's a simple example:

yamlCopier le code

stages:
 - print-something

user-deletion-prevention-check-job:
 stage: print-something
 script:
   - echo "Printing something....."
 tags:
   - test-runner

If your looking for a managed gitlab runner, maybe you should look to what we built.

And that's it! You're now set to get started with GitLab self-managed runners.

Untitled UI logotext
© 2024 Cloud-Runner. All rights reserved.