top of page

LetsDevOps: How to Setup GitLab Runner for CI/CD Pipeline

Updated: Jan 3, 2023

Introduction

In this article we will understand what is GitLab Runner, how to setup and further we will learn to use in CI/CD pipeline.


What is GitLab Runner

GitLab runner is an application which helps to execute jobs in pipeline for CI/CD.


When we run pipeline all execution of the script and task happens through GitLab Runner. It can be installed on On-premise or on Cloud Infrastructure.


Why GitLab Runner

This is helpful when we want to configure our own build machine which further can be used for all the CI/CD pipeline.


Types of Runner

GitLab Runner --> Use by Tagged CI
Runner SaaS --> Use by untagged CI


Runner Scope

Runners are available based on who you want to have access:

  1. Shared Runner --> Available for All GitLab Groups & Projects and Groups

  2. Group Runner --> Available for All GitLab Projects and Sub Groups in a Group

  3. Specific Runner --> Specific to One Project


Architecture

ree


How to Setup GitLab Runner


ree

To setup GitLab Runner we need to first Install Runner and then register with GitLab.



Install Runner


Step 1: GitLab Project Settings -> CI / CD -> Runners section, and clicking Show runner installation instruction.



ree

Step 2: Download the GitLab Runner exe specific to required OS.


Step 3: Copy downloaded GitLab Runner exe to System where you want to configure the Runner.


Example: Like

C:\GitLab-Runner

ree

Step 4: Run the CMD as Admin/Elevated User

ree

cd C:\GitLab-Runner 
.\gitlab-runner.exe install



ree

Step 5: Verify is the service Installed after few minutes


ree

Step 6: Start the service


ree

Register Runner


After successful installation of runner now we need to register it with GitLab Project.


Follow this link for specific OS --> Register Runner



Step 1: Run the following command


.\gitlab-runner.exe register
ree

Step 2: Enter the GitLab Install detail can be found


GitLab --> Setting --> CI/CD --> Runner


ree

ree

Step 3: Enter Tags for the Runner --> windows-demo


Step 4: Enter the Runner description --> Demo test


Step 5: Enter Executor --> Shell


ree

Verify Runner

After the successful configuration you will see the Runner detail in the GitLab Portal.


ree
















How to use in YAML Pipeline

Now we can use this Runner in our YAML pipeline after defining the Tag at Job level.


stages:    
  - build
  - package
  - deploy

build-job:     
  stage: build
  tags:
    - windows-demo
  script:
    - write-host "Hello world"

Demo






Comments


bottom of page