Install and Register GitLab Runner

In this section, we will install and configure GitLab Runner - an essential agent for executing CI/CD jobs in GitLab.

Install GitLab Runner

  1. Prepare Environment Create Config Directory

Create directory and configuration file:

sudo mkdir -p /tools && vi tools/setup.sh
  1. Install Runner Install GitLab Runner

Add the following content to setup.sh:

#!/bin/bash
# Update package list
apt update -y

# Install GitLab Runner
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
apt install gitlab-runner

# Check version
gitlab-runner --version
  1. Verify Installation Check Version

Check version to ensure successful installation:

gitlab-runner --version

Configure Backend Runner

  1. Switch User Switch User
sudo -i
su gitlab-runner
cd
  1. Access GitLab Settings Access Settings

Navigate to Runner settings:

  • Settings → CI/CD → Runners
  • Click “New project runner”
  1. Configure Backend Runner Configure Runner

Set up configuration:

  • Tag: fcj-lab-runner-be
  • Select “Run untagged jobs”
  • Click “Create runner”

Tags help identify which types of jobs the runner will process. For example: backend jobs, frontend jobs.

  1. Register Runner Register Runner
# Register runner with token
gitlab-runner register --url https://gitlab.com --token [your-token]

# Enter information when prompted
- URL: https://gitlab.com
- Name: fcj-lab-runner-be
- Executor: shell
  1. Start Runner Start Runner
# Run in background
nohup gitlab-runner run > start-runner-be.txt 2>&1 &

# Check logs
tail -f start-runner-be.txt

Configure Frontend Runner

To handle jobs efficiently, we need to create a separate runner for frontend tasks.

  1. Create Frontend Runner Frontend Runner

Repeat the above steps with these details:

  • Tag: fcj-lab-runner-fe
  • Name: fcj-lab-runner-fe
  • Keep other configurations the same
  1. Verify Runners Verify Runners

Check runners list:

  • Backend: #42138335 (fcj-lab-runner-be)
  • Frontend: #42138385 (fcj-lab-runner-fe)