CI/CD with Gitlab

Install Gitlab Repositories

install dependencies:

sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

install repo:

curl | sudo bash

install gitlab community edition

EXTERNAL_URL="" yum install -y gitlab-ce

setelah selesai, bisa diakses via url


Install Gitlab Runner

install dependencies:

yum install -y yum-utils   device-mapper-persistent-data   lvm2

install docker untuk gitlab runner:

yum-config-manager     --add-repo
yum install docker-ce docker-ce-cli

jalankan daemon docker:

systemctl start docker

install runner gitlab:

curl -LJO
yum install git -y
rpm -i gitlab-runner_amd64.rpm

konfiurasi/register gitlab-runner

jalan perintah berikut:

gitlab-runner register

lalu akan muncul questions seperti berikut:

Please enter the gitlab-ci coordinator URL (e.g.
Enter the token you obtained from your GitLab instance:

Please enter the gitlab-ci token for this runner
Enter a description that will help you recognize it in the GitLab web interface. We recommend naming this instance something unique, like runner-bastion for clarity.

Please enter the gitlab-ci description for this runner
[yourhostname] runner-bastion
If relevant, you may enter the tags for code you will build with your runner. However, we recommend this is left blank at this stage. This can easily be changed from the GitLab interface later.

Please enter the gitlab-ci tags for this runner (comma separated):
Choose whether or not your runner should be able to run untagged jobs. This setting allows you to choose whether your runner should build repositories with no tags at all, or require specific tags. Select true in this case, so your runner can execute all repositories.

Whether to run untagged jobs [true/false]: true
Choose if this runner should be shared among your projects, or locked to the current one, which blocks it from building any code other than those specified. Select false for now, as this can be changed later in GitLab’s interface:

Whether to lock Runner to current project [true/false]: false
Choose the executor which will build your machines. Because we’ll be creating new Droplets using Docker, we’ll choose docker+machine here, but you can read more about the advantages of each approach in this compatibility chart:

Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
You’ll be asked which image to use for projects that don’t explicitly define one. We’ll choose a basic, secure default:

Please enter the Docker image (e.g. ruby:2.1):

status runner yg sudah terkoneksi:


Contoh sederhana konsep ci/cd di gitlab:

  1. Create Repo Test di Gitlab.
  2. Create file .gitlab-ci.yml , isikan seperti berikut: Untuk memahami bagian ini, kita harus tahu dulu referensi pipeline yg digunakan di gitlab. dokumentasi lengkap bisa dibaca di dalam contoh ini define stages ke dalam kedua kelompok, compile dan deploy .

    stages: - compile - deploy

setelah itu dari masing-masing kelompok, berikan task dalam variable script dan masukkan kelompok compile ke dalam stage:

  stage: compile
    - pwd;uname -a;uptime

untuk kelompok yg lain (deploy) sama seperti berikut:

  stage: deploy
    - ls /;uname -a

sesuaikan perintah task yg ada di script.

hasil akhir .gitlab-ci.yml:

  - compile
  - deploy

  stage: compile
    - pwd;uname -a;uptime

  stage: deploy
    - ls /;uname -a
  1. commit untuk memproses secara otomatis ci/cd




Next, kita akan coba deployment, automation testing, deliver apps dg konsep tsb lewat ci/cd gitlab.