GitLab CICD Learning Project-1


In this blog we are going to create a GitLab project, that will showcase the skillset regarding GitLab tool.
Create a Group and a project within
Open your GitLab account and follow these steps one by one. I will guide you if you are starting from basic, so you have to create a group, for this directly go to GitLab account and click on “New group“ button, there you will see two ways to create group, but you need to create a group by click on “Create Group“ . Give him a name and done, you have successfully created a group. In GitLab, your group is like user account in GitHub, ex: GitHub-username
Now in this group, you have to create project by pressing “New Project“ button exact same way of group creation. This is like repository in your GitHub account.
Push your application data to project
As a developer you need to push all the project code from your system to GitLab project using Git Tool.
Here i have pushed all the project code in master branch.
Link: https://gitlab.com/devrakaops1/java-todo-app-cicd/-/tree/master?ref_type=heads
Add a Runner
now this time your next work is to create a EC2-Instance that we can use as a GitLab custom Runner to run our project.
Step-1: Go to your AWS account and create an ec2-instance with t2.medium and rhel-9 OS
Step-2: Take SSH to the instance and run provided commands to make them GitLab Runner
Now run commands to became GitLab Runner
Go to settings > CICD > Runners > Create Project Runner
And click on “Create Runner“
Now select your OS “RedHat Linux“ in my case.
Now you have to run some commands but GitLab Runner must be installed before you can register a runner. For this run below commands by clicking in link “How do I install GitLab Runner?“
Select your architecture of system, run the following commands.
But don’t forgot to run command “yum update“. This will save your time and to lots of confusions.
And then following command.
gitlab-runner register --url https://gitlab.com --token glrt-oxwG1lduWEnIh3DJiwHCqm86MQpwOjE3ZmVkeQp0OjMKdTpobDhpbRg.01.1j0181m9p
Now check your runner is working and active
make sure you have turn off GitLab default runner
Now your runner is active and in working state. Later you can mention this runner using mentioning tags “dev“ in main CICD file .gitlab-ci.yml
Add Docker Credentials Variables
To add variable in GitLab, go to settings > CICD > Variables > add variable
We have to create two variable:
DOCKERHUB_NAME = ********
DOCKERHUB_PASS = *****************************
Now its time to create CICD file. Name should be “.gitlab-ci.yml
“
Create a GitLab CICD file
stages:
- build
- test
- push_to_dockerhub
- deploy
variables:
NAME: "Rakesh"
CITY: "Jaipur"
build_job:
stage: build
script:
- echo "$CI_JOB_STAGE is working in $CI_COMMIT_BRANCH branch"
- docker build -t todo-app:latest .
tags:
- dev
test_job:
stage: test
script:
- echo "$CI_JOB_STAGE is working in $CI_COMMIT_BRANCH branch"
- docker image ls
tags:
- dev
push_job:
stage: push_to_dockerhub
before_script:
- docker login -u $DOCKERHUB_NAME -p $DOCKERHUB_PASS
script:
- echo "$CI_JOB_STAGE is working in $CI_COMMIT_BRANCH branch"
- docker image tag todo-app:latest $DOCKERHUB_NAME/todo:latest
- docker push $DOCKERHUB_NAME/todo:latest
tags:
- dev
deploy_job:
stage: deploy
script:
- echo "$CI_JOB_STAGE is working in $CI_COMMIT_BRANCH branch"
- docker compose up -d
- echo "Working Successful"
tags:
- dev
Install Docker in Ec2 Instance
Install docker: https://docs.docker.com/engine/install/centos/
systemctl enable --now docker
Configuration Work
yum install -y git
echo "gitlab-runner ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/gitlab-runner
Check the CICD pipeline
When you pushes the code to the repository server in master branch, automatically cicd pipeline will trigger.
Go to build > pipeline >
If you want to see on instance, there is docker container is running on port 8000.
So we have to add 8000 inbound port to the AWS EC2-Instances security group
Access the application
Because we have deployed application on ec2-instance so will see the output using instances public IP with appending 8000 port on web browser.
Notification Alerts
GitLab normally provides alert notification service
Output Logs
Build_job
Running with gitlab-runner 18.3.0 (9ba718cd) on gitlab-runner1 jHBjwSbnw, system ID: s_5da8ab1e406d Preparing the "shell" executor 00:00 Using Shell (bash) executor... Preparing environment 00:00 Running on ip-172-31-95-28.ec2.internal... Getting source from Git repository 00:01 Gitaly correlation ID: 089ad318cb6440518c7c06d9f9afc0ee Fetching changes with git depth set to 20... Reinitialized existing Git repository in /builds/jHBjwSbnw/0/devrakaops1/java-todo-app-cicd/.git/ Checking out 65f03dd9 as detached HEAD (ref is master)... Skipping Git submodules setup Executing "step_script" stage of the job script 00:08 $ echo "Hello my name is $NAME and i lived in $CITY" Hello my name is Rakesh and i lived in Jaipur $ echo "$CI_JOB_STAGE is working in $CI_COMMIT_BRANCH branch" build is working in master branch $ echo pwd pwd $ echo whoami whoami $ echo ls -al ls -al $ docker build -t todo-app:latest . #0 building with "default" instance using docker driver #1 [internal] load build definition from Dockerfile #1 transferring dockerfile: 297B done #1 DONE 0.0s #2 [auth] library/node:pull token for registry-1.docker.io #2 DONE 0.0s #3 [internal] load metadata for docker.io/library/node:12.2.0-alpine #3 DONE 0.2s #4 [internal] load .dockerignore #4 transferring context: 2B done #4 DONE 0.0s #5 [1/5] FROM docker.io/library/node:12.2.0-alpine@sha256:2ab3d9a1bac67c9b4202b774664adaa94d2f1e426d8d28e07bf8979df61c8694 #5 DONE 0.0s #6 [internal] load build context #6 transferring context: 15.71kB done #6 DONE 0.0s #7 [2/5] WORKDIR /node #7 CACHED #8 [3/5] COPY . . #8 DONE 0.0s #9 [4/5] RUN npm install #9 0.710 npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it! #9 5.604 #9 5.604 > ejs@2.7.4 postinstall /node/node_modules/ejs #9 5.604 > node ./postinstall.js #9 5.604 #9 5.653 Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/) #9 5.653 #9 5.909 npm WARN my-todolist@0.1.0 No repository field. #9 5.910 npm WARN my-todolist@0.1.0 No license field. #9 5.910 #9 5.913 added 291 packages from 653 contributors and audited 291 packages in 5.249s #9 5.914 found 33 vulnerabilities (10 low, 3 moderate, 16 high, 4 critical) #9 5.914 run `npm audit fix` to fix them, or `npm audit` for details #9 DONE 6.1s #10 [5/5] RUN npm run test #10 0.428 #10 0.428 > my-todolist@0.1.0 test /node #10 0.428 > mocha --recursive --exit #10 0.428 #10 0.624 #10 0.625 #10 0.627 Simple Calculations #10 0.628 This part executes once before all tests #10 0.628 Test1 #10 0.628 executes before every test #10 0.629 ✓ Is returning 5 when adding 2 + 3 #10 0.629 executes before every test #10 0.630 ✓ Is returning 6 when multiplying 2 * 3 #10 0.630 Test2 #10 0.630 executes before every test #10 0.630 ✓ Is returning 4 when adding 2 + 3 #10 0.630 executes before every test #10 0.630 ✓ Is returning 8 when multiplying 2 * 4 #10 0.631 This part executes once after all tests #10 0.631 #10 0.631 #10 0.631 4 passing (7ms) #10 0.631 #10 DONE 0.6s #11 exporting to image #11 exporting layers #11 exporting layers 1.1s done #11 writing image sha256:c210dbc115207b92008265a12fe9e3059e2b259a59627ce44805f917bb2c49dd done #11 naming to docker.io/library/todo-app:latest done #11 DONE 1.1s Cleaning up project directory and file based variables 00:00 Job succeeded
test_job
Running with gitlab-runner 18.3.0 (9ba718cd) on gitlab-runner1 jHBjwSbnw, system ID: s_5da8ab1e406d Preparing the "shell" executor 00:00 Using Shell (bash) executor... Preparing environment 00:00 Running on ip-172-31-95-28.ec2.internal... Getting source from Git repository 00:01 Gitaly correlation ID: 14a70c8d29bf4a60bb71afd99d959466 Fetching changes with git depth set to 20... Reinitialized existing Git repository in /builds/jHBjwSbnw/0/devrakaops1/java-todo-app-cicd/.git/ Checking out 65f03dd9 as detached HEAD (ref is master)... Skipping Git submodules setup Executing "step_script" stage of the job script 00:00 $ echo "$CI_JOB_STAGE is working in $CI_COMMIT_BRANCH branch" test is working in master branch $ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE todo-app latest c210dbc11520 5 seconds ago 104MB [MASKED]/todo latest 5970356deaa0 3 minutes ago 104MB Cleaning up project directory and file based variables 00:00 Job succeeded
push_to_dockerhub_job
Running with gitlab-runner 18.3.0 (9ba718cd) on gitlab-runner1 jHBjwSbnw, system ID: s_5da8ab1e406d Preparing the "shell" executor 00:00 Using Shell (bash) executor... Preparing environment 00:00 Running on ip-172-31-95-28.ec2.internal... Getting source from Git repository 00:01 Gitaly correlation ID: 4cfb3d55ef244d9dad1a96d22cdd7691 Fetching changes with git depth set to 20... Reinitialized existing Git repository in /builds/jHBjwSbnw/0/devrakaops1/java-todo-app-cicd/.git/ Checking out 65f03dd9 as detached HEAD (ref is master)... Skipping Git submodules setup Executing "step_script" stage of the job script 00:04 $ echo "$CI_JOB_STAGE is working in $CI_COMMIT_BRANCH branch" push_to_dockerhub is working in master branch $ docker login -u $DOCKERHUB_NAME -p $DOCKERHUB_PASS WARNING! Using --password via the CLI is insecure. Use --password-stdin. Login Succeeded $ docker image tag todo-app:latest $DOCKERHUB_NAME/todo:latest $ docker push $DOCKERHUB_NAME/todo:latest The push refers to repository [docker.io/[MASKED]/todo] b4a20abeed57: Preparing b5a342a444fe: Preparing 2630b0641421: Preparing 48568d6a9c95: Preparing 917da41f96aa: Preparing 7d6e2801765d: Preparing f1b5933fe4b5: Preparing 7d6e2801765d: Waiting f1b5933fe4b5: Waiting 48568d6a9c95: Layer already exists 917da41f96aa: Layer already exists 7d6e2801765d: Layer already exists f1b5933fe4b5: Layer already exists b4a20abeed57: Pushed 2630b0641421: Pushed b5a342a444fe: Pushed latest: digest: sha256:c289ae82475448c92ba2db4d00584f9664fdc9bc300208a44dbc7c878c6623c0 size: 1785 Cleaning up project directory and file based variables 00:01 Job succeeded
deploy_job
Running with gitlab-runner 18.3.0 (9ba718cd) on gitlab-runner1 jHBjwSbnw, system ID: s_5da8ab1e406d Preparing the "shell" executor 00:00 Using Shell (bash) executor... Preparing environment 00:00 Running on ip-172-31-95-28.ec2.internal... Getting source from Git repository 00:01 Gitaly correlation ID: 45752bebf3ae4b6582bb25bdff2e7ac4 Fetching changes with git depth set to 20... Reinitialized existing Git repository in /builds/jHBjwSbnw/0/devrakaops1/java-todo-app-cicd/.git/ Checking out 65f03dd9 as detached HEAD (ref is master)... Skipping Git submodules setup Executing "step_script" stage of the job script 00:01 $ echo "$CI_JOB_STAGE is working in $CI_COMMIT_BRANCH branch" deploy is working in master branch $ docker compose up -d time="2025-08-22T15:30:00Z" level=warning msg="/builds/jHBjwSbnw/0/devrakaops1/java-todo-app-cicd/docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion" Network java-todo-app-cicd_default Creating Network java-todo-app-cicd_default Created Container java-todo-app-cicd-web-1 Creating Container java-todo-app-cicd-web-1 Created Container java-todo-app-cicd-web-1 Starting Container java-todo-app-cicd-web-1 Started $ echo "Working Successful" Working Successful Cleaning up project directory and file based variables 00:00 Job succeeded
Thank you
GitLab repo: https://gitlab.com/devrakaops1/java-todo-app-cicd/-/tree/master?ref_type=heads
Subscribe to my newsletter
Read articles from Rakesh Kumar Jangid directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Rakesh Kumar Jangid
Rakesh Kumar Jangid
Let's learn together and serve the society, Make India Proud.