Sometimes we perform specific tasks through Gitlab-CI, which may not be supported by the shared Gitlab-Runner provided within the company. At this point we can perform these special tasks by registering a private runner with GitLab to run locally.

To run Runner locally and register with GitLab, there are roughly three steps:

  • Install the git-runner program locally
  • Create a runner and register with GitLab
  • Start local runner

Install the git-runner program locally

Gitlab – runner support in a lot of the installation of the operating system environment (docs.gitlab.com/runner/inst…

1. Download binaries for your system:

sudo curl --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64"
Copy the code

You can download the binaries for each available version by clicking here.

2. Grant execution permission:

sudo chmod +x /usr/local/bin/gitlab-runner
Copy the code

At this point, the GitLab program has been successfully installed on our machine. This can be verified by executing the relevant commands on the command line:

Install using Brew for macOS

The gitlab-Runner program is also supported on macOS via BREW and can be installed using the following names:

brew install gitlab-runner

brew services start gitlab-runner

Copy the code

Create a runner and register with GitLab

It is also easy to create and register a runner on macOS. You can interactively register a local runner to gitlab with the following command:

gitlab-runner register
Copy the code

After running this command, there is a list of runner information for you to fill in:

After the command is complete, we have registered the Runner with GitLab. At this point, we can see our registered runner information on the GitLab project page (Project page > Settings >CI/CD>Runners>Specific Runners) :

Under Available Specific Runners, we can see our newly registered runner. However, we can see that our newly registered runner is still disconnected because our runner has not been started.

Start local runner

After registration, we just need to run our Gitlab-Runner locally to make the Runner work in GitLab. To switch the system user to the current user, run the following command:

su - <username>
Copy the code

Install and start GitLab Runner as a service:

cd ~
gitlab-runner install
gitlab-runner start
Copy the code

At this point our runner has registered and started. Wait a few minutes, then go to the GitLab page to observe, we can see that our runner has handled the online state, we can use it to perform the task.

Use private Runners to run tasks

Edit tasks to be run using local Runner in.gitlab-ci.yml

As shown in the figure above, specify the tag as the local runner’s tag. After submitting the code, you can see that the triggered Gitlab CI job will run in our newly registered local runner 👌 :