Easy steps to setup your own gitlab runner on GitLab or locally

Reza Rezvani
4 min readJan 28, 2023

--

However, I can provide you with instructions on how to set up a GitLab Runner.

  1. First, make sure you have a GitLab account and a project that you want to run the runner on.
  2. Next, log in to your GitLab account and navigate to the project you want to run the runner on.
  3. Go to the “Settings” menu and select “CI/CD” from the options.
  4. In the “Runners” section, click on the “Expand” button to reveal the options.
  5. Click on the “Set up a specific Runner manually” button.
  6. On the next page, you will be provided with a command that you need to run on the machine you want to use as a runner. The command will look something like this:
sudo gitlab-runner register
  1. Run the command on the machine and follow the prompts to complete the registration process.
  2. After the registration process is complete, the runner should be available in the project’s “Runners” section in GitLab.

How to run GitLab runner on your local machine

You can run a GitLab Runner locally on your machine. To do this, you will need to install the GitLab Runner software on your local machine and then register the runner with your GitLab instance.

Here are the general steps you would need to follow:

  1. Download and install the GitLab Runner software on your local machine. The installation process will vary depending on your operating system.
  2. Once the installation is complete, open a terminal and run the following command to register the runner with your GitLab instance:
sudo gitlab-runner register
  1. Follow the prompts to complete the registration process. You will need to provide your GitLab instance URL, the registration token for your project, and any other information the registration process requires.
  2. Once the registration process is complete, the runner should be available in the project’s “Runners” section in GitLab.
  3. Configure your local runner to run your pipeline

Please keep in mind that using a local runner for your pipeline can have some limitations, such as lack of scalability and availability, compared to using a runner on a dedicated machine or in a cloud environment

Also, be aware that you need to have the required dependencies installed on your local machine, such as proper version of ruby, or any other language or tool that your pipeline is using.

Can you show me an example code for the runner

Sure, here’s an example of a .gitlab-ci.yml file that configures a simple pipeline for a project.

stages:
- build
- test
- deploy
build:
stage: build
script:
- echo "Building the project..."
- make build
test:
stage: test
script:
- echo "Running tests..."
- make test
deploy:
stage: deploy
script:
- echo "Deploying the project..."
- make deploy

This example defines three stages for the pipeline: build, test, and deploy. Each stage is defined as a job, and each job is composed of one or more script commands that are executed in order.

In this example, the pipeline will:

  • Build the project
  • Run tests
  • Deploy the project

You can use your own commands and scripts to suit your needs and dependencies.

Please note that this is a simple example, and in a real-world scenario, you would likely have more complex pipelines with multiple jobs and stages that are tailored to your specific needs. Also, you might want to include variables, cache and artifacts management, and more options that GitLab CI/CD provides.

If you have any more questions or need more information, please let me know.

Docker + GitLab

Here is another way to use it with Docker

You can also use Docker with GitLab Runner to run your pipeline in a containerized environment. This allows you to ensure that your pipeline runs consistently across different machines and environments, and makes it easy to manage dependencies and isolate your pipeline from other processes running on the same machine.

Here’s an example of how you can use Docker with GitLab Runner:

  1. First, you will need to make sure that Docker is installed on the machine where you’re running the GitLab Runner.
  2. Next, you will need to configure your .gitlab-ci.yml file to use a Docker image for your pipeline. Here's an example of how you can do this:yamlCopy code
image: node:latest
stages:
- build
- test
- deploy
build:
stage: build
script:
- echo "Building the project..."
- npm install
- npm run build
test:
stage: test
script:
- echo "Running tests..."
- npm test
deploy:
stage: deploy
script:
- echo "Deploying the project..."
- make deploy

In this example, the image key is set to node:latest, which tells GitLab Runner to use the latest version of the official Node.js image from Docker Hub. This will ensure that the pipeline runs in a container with the correct version of Node.js and any other dependencies specified in the image.

  1. You will also need to configure your runner to use the Docker executor. This can be done by editing the config.toml file for the runner, and adding the following under the [[runners]] section:
executor = "docker"
  1. Once you have completed these steps, the pipeline will be run inside a container using the specified image, ensuring that the pipeline runs consistently across different machines and environments.

You can also use a specific version of the image, use your own image, or use other options that are offered by GitLab Runner and Docker, such as multi-stage build, volumes, and more.

Please let me know if you have any further questions or if there’s anything else I can help with.

Happy installing!

Cheers

Reza Rezvani — Jan. 2023, Berlin

--

--

Reza Rezvani
Reza Rezvani

Written by Reza Rezvani

As CTO of a Berlin AI MedTech startup, I tackle daily challenges in healthcare tech. With 2 decades in tech, I drive innovations in human motion analysis.

No responses yet