GitLab Runner supports multiple executors, but Shell and Docker are the most commonly used for C/C++ CI/CD pipelines on Linux.
- Both are easy to configure
- Selection depends on: System restrictions, Security policies and Resource availability
Executors Overview
Shell Executor
- Runs jobs directly on the host machine
- Requires manual installation of dependencies
- Faster execution (no container overhead)
- Limited isolation → potential dependency conflicts
Best for:
- Dedicated servers
- Controlled environments
Docker Executor
- Runs jobs inside containers
- No manual dependency setup required
- Provides isolated, reproducible builds
- Slight startup overhead
Best for:
- Team environments
- Scalable CI/CD pipelines
- Microservices architecture
C/C++ CI/CD with Shell Executor
Software Requirements
Install the following:
- Git : version control
- CMake : build automation
- GCC / G++ : C/C++ compilers
- grep : optional (for text processing in scripts)
Verify Installation
which git
gcc --version
g++ --version
cmake --version
GitLab Runner Setup (Linux)
1. Download Binary
sudo curl -L --output /usr/local/bin/gitlab-runner \
https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
2. Grant Execute Permission
sudo chmod +x /usr/local/bin/gitlab-runner3. Create Runner User
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash4. Install as Service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner5. Start Runner
sudo gitlab-runner startRegister Runner
sudo gitlab-runner registerProvide:
- GitLab instance URL (e.g., http://gitlab.example.com)
- Project registration token
(GitLab → Project → Settings → CI/CD → Runners) - Runner description (any name)
- Tags (optional but recommended)
- Executor: shell
Shell Executor: .gitlab-ci.yml
stages:
- build
- test
build_job:
stage: build
only:
- master
script:
- cd sourcecode
- chmod +x BuildPackage.sh
- ./BuildPackage.sh
artifacts:
expire_in: 7 days
paths:
- sourcecode/binaryfolder_name
test_job:
stage: test
only:
- master
script:
- cd testdir
- chmod +x tests.sh
- ./tests.sh
dependencies:
- build_job
Java CI/CD with Docker Executor
Key Advantages
- No manual installation required
- Clean, isolated environment
- Consistent builds across systems
Recommended Approach
- Use prebuilt images instead of installing packages every run
- Custom Docker images with required tools
Docker Executor: .gitlab-ci.yml
image: gcc:latest
stages:
- build
- test
before_script:
- apt-get update && apt-get install -y cmake
build_job:
stage: build
script:
- cd sourcecode
- chmod +x BuildPackage.sh
- ./BuildPackage.sh
artifacts:
expire_in: 7 days
paths:
- sourcecode/binaryfolder_name
test_job:
stage: test
script:
- cd testdir
- chmod +x tests.sh
- ./tests.sh
dependencies:
- build_job
Add Caching
cache:
paths:
- build/
Use Runner Tags
tags:
- docker
Common GitLab Runner Commands
| Command | Purpose |
|---|---|
| gitlab-runner register | Register runner |
| gitlab-runner start | Start runner |
| gitlab-runner stop | Stop runner |
| gitlab-runner status | Check status |
| gitlab-runner restart | Restart service |
| gitlab-runner unregister --all-runners | Remove all runners |
| gitlab-runner --help | List commands |
gitlab-runner --debug | Debug mode |