VOOZH about

URL: https://www.geeksforgeeks.org/cpp/implementation-of-ci-cd-in-c-c-applicationlinux-using-shell-and-docker-executor-on-gitlab/

⇱ Implementation of CI/CD in C/C++ Application (Linux) Using Shell and Docker Executor on GitLab - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Implementation of CI/CD in C/C++ Application (Linux) Using Shell and Docker Executor on GitLab

Last Updated : 2 May, 2026

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-runner

3. Create Runner User

sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

4. Install as Service

sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner

5. Start Runner

sudo gitlab-runner start

Register Runner

sudo gitlab-runner register

Provide:

  • 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

CommandPurpose
gitlab-runner registerRegister runner
gitlab-runner startStart runner
gitlab-runner stopStop runner
gitlab-runner statusCheck status
gitlab-runner restartRestart service
gitlab-runner unregister --all-runnersRemove all runners
gitlab-runner --helpList commands

gitlab-runner --debug

Debug mode

Comment
Article Tags:
Article Tags: