GitLab System Administration - Hands-on Lab: Configure GitLab Runners

This Hands-On Guide walks you through installing and managing a GitLab Runner on a virtual machine.

Estimated time to complete: 40 minutes

Task A. Install the gitlab-runner package

  1. Use your assigned IP address and SSH key file to log into your GitLab Runner server (not your Omnibus server).
1
ssh -i YOUR_ASSIGNED_SSH_KEYFILE ec2-user@YOUR_RUNNER_SERVER_PUBLIC_IP
  1. If your system displays an authentication warning, type yes and press Enter

  2. Add the GitLab Runner installation repository.

1
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
  1. Install the GitLab Runner agent.
1
sudo dnf install -y gitlab-runner
  1. Once the install completes, check that the service is running.
1
sudo gitlab-runner status

Task B. Register a runner with GitLab

  1. Sign into your GitLab instance with a web browser and select Menu > Admin Area.

  2. In the left sidebar, under CI/CD, select Runners.

  3. Select New instance runner.

  4. In the Operating systems section, select Linux.

  5. In the Tags section, select Run untagged jobs.

This will allow the runner to pick up any jobs rather than just jobs with specific tags.

  1. Leave all other options as default and select Create runner.

  2. Copy the command in Step 1 and run it in your command prompt.

  3. The command will first prompt you for your GitLab instance URL. Verify that this URL matches your GitLab instance, then press Enter

  4. Enter any appropriate name for your runner.

  5. When you are prompted for an executor, type shell.

A shell executor will run jobs using your instance’s shell. For more information about executors, check the documentation.

  1. Run sudo gitlab-runner list to verify the runner after registration.

  2. Return to your web browser and select Go to runners page. Verify the runner you registered appears in the list and shows as online.

Task C. Test the runner with a CI/CD pipeline

  1. Navigate back to the homepage of your GitLab instance by selecting the GitLab icon at the top of the left sidebar.

  2. Select Create a project.

  3. Select Create blank project.

  4. Enter CICD Test as the project name.

  5. In the Project URL, select root from the namespace dropdown.

  6. Leave all other settings as they are and click Create project.

  7. In the middle of the project landing page, under the project title, select the + dropdown. Select New file.

  8. On the new file page, enter .gitlab-ci.yml as the file name.

  9. Paste the following code into the body of the file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
stages:
  - build
  - test

build_app:
  stage: build
  script:
    - echo "The build stage requires at least one job"

test_app:
  stage: test
  script:
    - echo "The test stage requires at least one job"
  1. Select Commit changes.

  2. In the left sidebar, select Build > Pipelines.

  3. Select the pipeline status (it should say passed).

  4. Click into each of the build_app and test_app jobs to see the job logs and commands that were executed on the runner.

Lab Guide Complete

You have completed this lab exercise. You can view the other lab guides for this course.

Suggestions?

If you’d like to suggest changes to the GitLab System Admin Hands-on Guide, please submit them via merge request.

Last modified April 26, 2024: Update Lab Descriptions (05f28a88)