Gitlab CI Runner
This example demonstrates how to configure a Gitlab CI pipeline to run jobs on different runners. We'll use three runners: a default runner, a shell runner, and a docker runner. Each runner will execute a simple script that prints the current directory, a message indicating the runner type, the current date and time, and the hostname.
Configuration
The following YAML configuration defines the stages and jobs for our pipeline:
---
stages:
- default
- shell
- docker
default-run:
stage: default
script:
- echo $CI_PROJECT_DIR
- echo "Running on the default runner"
- date
- hostname
shell-run:
stage: shell
tags:
- shell
script:
- echo $CI_PROJECT_DIR
- echo "Running on the shell runner"
- date
- hostname
docker-run:
stage: docker
image: busybox:latest
tags:
- docker
script:
- echo $CI_PROJECT_DIR
- echo "Running on the docker runner"
- date
- hostname
Explanation
Stages
The stages
section defines the order of execution for the jobs. In this case, the jobs will run in the order: default
, shell
, and docker
.
Jobs
Each job (default-run
, shell-run
, docker-run
) specifies the stage it belongs to and the script to execute. The shell-run
and docker-run
jobs also specify tags to ensure they run on the appropriate runners.
Runners
You'll need to configure separate Gitlab runners with the appropriate tags (shell
and docker
) to execute the corresponding jobs. The default job will run on any available runner.