Skip to main content
Version: v4 (current)

Gitlab Pipelines

Gitlab pipeline runners support multiple installation and runtime configurations. This guide will create a very basic runner using the shell executor in order to avoid running docker-in-docker. This guide provides both manual and automated setup instructions, skip to the bottom of the page for the automation script.

You may find more in-depth information regarding Gitlab Runners at the following links:

Manual

  1. Download and install the Gitlab runner application on your host

    # Download the binary for your system
    sudo 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
    sudo chmod +x /usr/local/bin/gitlab-runner

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

    # Install and run as a service
    sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
    sudo gitlab-runner start
  2. Log in to Gitlab and navigate to the repo you want to create a runner for



  1. From the menu on the left, select Settings then choose CI/CD from the pop-out list.


  1. Find the Runners section and click the expand button


  1. Select New Project Runner


  1. Choose Linux as the operating system


  1. Optionally, check the Run untagged jobs box if you would liek your runner to be the default for all jobs.


  1. Click the Create Runner button at the bottom of the page


  1. Follow the instructions provided to register your runner


Automated

The following script will perform the same actions as described above automatically. This is usefull for those who would prefer ephemeral runners or to use a declarative workflow. You will need to provide your own project access-token to the script as an input value. For mor in-depth information see the following resources:

  1. From the main page of your Gitlab repository, select the Settings option from the menu on the left.


  1. Select the Access Tokens menu


  1. Select Add new token


  1. Give the new token a name and expiration date


  1. Set the following role and scopes for the token:


  1. Click the Create Token button


  1. Save the token string somewhere secure


  1. Copy and paste the following into your terminal to create the script

    /usr/bin/cat << 'EOF' > runner.sh
    #!/bin/bash

    export DOWNLOAD_URL="https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb"

    curl -LJO "${DOWNLOAD_URL}"
    sudo dpkg -i gitlab-runner_amd64.deb

    export GITLAB_URL=$1
    export PROJECT_ID=$2
    export GITLAB_TOKEN=$3

    RETURN=$(curl --silent --request POST --url "$GITLAB_URL/api/v4/user/runners" \
    --data "runner_type=project_type" \
    --data "project_id=$PROJECT_ID" \
    --data "description=gameci runner" \
    --data "tag_list=" \
    --header "PRIVATE-TOKEN: $GITLAB_TOKEN")

    TOKEN=$(echo $RETURN |jq -r '.token')

    sudo gitlab-runner register \
    --non-interactive \
    --name "gameci-runner" \
    --url "$GITLAB_URL" \
    --token "$TOKEN" \
    --executor "shell" \
    --docker-image ubuntu:latest

    sudo usermod -aG docker gitlab-runner
    EOF
  2. Run the script as follows:

    bash ./runner.sh <gitlab-url> <project-id> <project-token>