Implementation of CI/CD in Java application (Linux) Using Shell and Docker Executor on GitLab

Last Updated : 29 May, 2026

GitLab Runner supports multiple executors, with Shell and Docker being the most widely used for CI/CD pipelines. The choice depends on system constraints, security policies, and scalability requirements.

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

Java CI/CD with Shell Executor

Software Requirements

Install the following:

  • Git : version control
  • JDK (e.g., OpenJDK 8+) : compile Java code
  • Apache Ant : build automation

Verify Installation

which git
java -version
ant -version

GitLab Runner Setup

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

- execute


build:

stage: build

script:

- ant -f build.xml

artifacts:

paths:

- abc.jar


execute:

stage: execute

script:

- cd scripts

- chmod +x run.sh

- ./run.sh

Java CI/CD with Docker Executor

  • Use prebuilt images instead of installing packages every run
  • Prefer openjdk images over generic OS images

Docker Executor: .gitlab-ci.yml

image: openjdk:8


stages:

- build

- execute


before_script:

- apt-get update && apt-get install -y ant


build:

stage: build

script:

- ant -f build.xml

artifacts:

paths:

- abc.jar


execute:

stage: execute

script:

- cd scripts

- chmod +x run.sh

- ./run.sh

Add Caching

cache:

paths:

- .ant/

Use Runner Tags

tags:

- shell

Common GitLab Runner Commands

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