Create Continuous Integration (CI) Pipeline in Gitlab


  1. What is Continuous Integration (CI)? What it is the application?
  2. How does a CI Pipeline work?
  3. What do I need for a CI Pipeline? What steps are necessary?
  4. Small Project in Python
  5. Server Configuration

Python Project

Gitlab CI Yaml File

  - test

  stage: test
  image: python:3.9
    - pip3 install pipenv
    - pipenv install
    - pipenv run python3 -m pytest

Server Configuration

Server Update

# SSH Login
~ ssh root@IP-Adresse
# Update Server
root@server:~$ apt-get update && apt-get upgrade

Create new user

# Create new user
root@server:~$ useradd -m -s /bin/bash youtube
# Change Password
root@server:~$ passwd youtube
# Add user to sudo Group
root@server:~$ usermod -aG sudo youtube

Disable root access per ssh

# Edit SSH Config
youtube@server:~$ sudo vim /etc/ssh/sshd_config

# inside vim 
yes mit no ersetzen

# on your keyboard
# Restart ssh service
root@server:~$ sudo systemctl restart ssh

Password-less login + Installation of Docker

# on your Laptop / PC
~ ssh-copy-id youtube@server-IP
# Login mit youtube ohne Passwort

# Installation of Docker
youtube@server:~$ sudo apt-get install -y

# Adding user to docker group
root@server:~$ usermod -aG docker $USER

# Logout and login again

Checking of docker installation

# Testen der Docker Installation
youtube@server:~$ docker ps
# Beispiel Container starten
youtube@server:~$ docker run hello-world

Install Gitlab Runner

# Start Gitlab Runner
# Resource:
youtube@server:~$ docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner \
     -v /var/run/docker.sock:/var/run/docker.sock \

# Register Gitlab Runner-> write oder your Gitlab Instanz Resource:
youtube@server:~$ docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register