Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Creating and Using GitLab Runners and Executors
79%

Using Linux Runner

To create a Linux runner, we will use our "dev" machine as an environment where all the jobs will be executed by the runner. First, we will install the GitLab runner on the machine:

# Download the binary for your system
curl -L \
--output /usr/local/bin/gitlab-runner \
https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

# Give it permission to execute
chmod +x /usr/local/bin/gitlab-runner

# Create a GitLab Runner user
useradd \
--comment 'GitLab Runner' \
--create-home gitlab-runner \
--shell /bin/bash

# Install the runner as a service
gitlab-runner install \
--user=gitlab-runner \
--working-directory=/home/gitlab-runner

# Run gitlab-runner as a service
gitlab-runner start

# Check the status of the service
gitlab-runner status

# Add the gitlab-runner user to the sudoers file 
# to allow it to run commands as root
echo "gitlab-runner ALL=(ALL) NOPASSWD:ALL" | \
sudo tee -a /etc/sudoers

Now, we need to register the runner with GitLab. Run the following command:

# Register the runner
gitlab-runner register \
--url https://gitlab.com/ \
--token $GITLAB_RUNNER_TOKEN \
--name "My Linux Runner" \
--executor shell \
--shell bash \
--non-interactive

The configuration options will be saved in the /etc/gitlab-runner/config.toml file. You can check the contents of the file to verify the configuration:

concurrent = 1
check_interval = 0
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "My Linux Runner"
  url = "https://gitlab.com/"
  id = ******
  token = "glrt-*******"
  token_obtained_at = 2024-08-24T14:29:15Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "shell"
  shell = "bash"
  [runners.custom_build_dir]
  [runners.cache]
    MaxUploadedArchiveSize = 0
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Enroll now to unlock all content and receive all future updates for free.