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
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 startLog in to Gitlab and navigate to the repo you want to create a runner for
![](/assets/images/gl-runner-repo-page-3d8d860bbfc40bbc712b018c19cc7765.png)
- From the menu on the left, select
Settings
then chooseCI/CD
from the pop-out list.
![](/assets/images/gl-runner-cicd-menu-8771d0e972037cf100a5139c8a2cabfc.png)
- Find the
Runners
section and click theexpand
button
![](/assets/images/gl-runner-cicd-settings-e7b869119297b43a78c70cc7a13545f2.png)
- Select
New Project Runner
![](/assets/images/gl-runner-new-runner-bd495cd8773542a9dfcd727c173d1fb3.png)
- Choose
Linux
as the operating system
![](/assets/images/gl-runner-select-os-19cc25a4a73b919f68fddcad34097a80.png)
- Optionally, check the
Run untagged jobs
box if you would liek your runner to be the default for all jobs.
![](/assets/images/gl-runner-tags-6a54cde90bc01a195422ecfdb56097c5.png)
- Click the
Create Runner
button at the bottom of the page
![](/assets/images/gl-runner-create-runner-624337840f7633f0cd1c98ab6e827568.png)
- Follow the instructions provided to register your runner
![](/assets/images/gl-runner-register-runner-990a92749115537492600894d0ca28c1.png)
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:
- Tutorial: Create, register, and run your own project runner
- Tutorial: Automate runner creation and registration
- Runner Executors
- From the main page of your Gitlab repository, select the
Settings
option from the menu on the left.
![](/assets/images/gl-runner-repo-page-3d8d860bbfc40bbc712b018c19cc7765.png)
- Select the
Access Tokens
menu
![](/assets/images/gl-runner-access-token-select-f452e4d8935cb1229f086ce334a2aea2.png)
- Select
Add new token
![](/assets/images/gl-runner-access-token-screen-f584f29da9f264b0ccd264568b46e1fc.png)
- Give the new token a name and expiration date
![](/assets/images/gl-runner-token-name-e77b6a1a541b046c0f1cc85f21fea394.png)
- Set the following role and scopes for the token:
![](/assets/images/gl-runner-token-role-50425fe61c4e47bc34615018e297a867.png)
- Click the
Create Token
button
![](/assets/images/gl-runner-token-create-button-eda8a21430d2c563622372f305316e3f.png)
- Save the token string somewhere secure
![](/assets/images/gl-runner-token-complete-387c483f581e511c5eadaae97a6b7382.png)
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
EOFRun the script as follows:
bash ./runner.sh <gitlab-url> <project-id> <project-token>