How To Integrate GitLab With Jenkins

To Integrate GitLab with Jenkins

Introduction:

One of the basic steps of implementing CI/CD is integrating the Source Control Management tool with your CI tool which saves you time and keeps your project updated all the time. One of the most popular and valuable SCM tools is GitLab. In this blog, I will explain how to integrate Jenkins with GitLab projects.

Step 1: Install Git by using the below command

[root@linuxhelp ~]# yum install git*
Rocky Linux 8 - AppStream                                          4.8 kB/s | 4.8 kB     00:00    
Rocky Linux 8 - AppStream                                          3.1 MB/s | 8.8 MB     00:02    
Rocky Linux 8 - BaseOS                                             3.1 kB/s | 4.3 kB     00:01    
Rocky Linux 8 - BaseOS                                             1.7 MB/s | 3.6 MB     00:02    
Rocky Linux 8 - Extras                                             3.6 kB/s | 3.5 kB     00:00    
Rocky Linux 8 - Extras                                             7.4 kB/s |  11 kB     00:01    
Jenkins                                                            8.4 kB/s | 2.9 kB     00:00    
Dependencies resolved.
===================================================================================================
 Package                     Arch     Version                                    Repository   Size
===================================================================================================
Installing:
 git                         x86_64   2.31.1-2.el8                               appstream   160 k

 git-all                     noarch   2.31.1-2.el8                               appstream    47 k

 git-clang-format            x86_64   13.0.1-2.module+el8.6.0+987+d36ea6a1       appstream    20 k
 git-core                    x86_64   2.31.1-2.el8                               appstream   4.7 M
 git-core-doc                noarch   2.31.1-2.el8                               appstream   2.6 M
 git-credential-libsecret    x86_64   2.31.1-2.el8                               appstream    54 k
 git-daemon                  x86_64   2.31.1-2.el8                               appstream   862 k
 git-email                   noarch   2.31.1-2.el8                               appstream    89 k
 git-gui                     noarch   2.31.1-2.el8                               appstream   306 k
 git-instaweb                noarch   2.31.1-2.el8                               appstream    62 k
 git-lfs                     x86_64   2.13.3-2.el8                               appstream   3.7 M
 git-subtree                 x86_64   2.31.1-2.el8                               appstream    70 k
 git-svn                     noarch   2.31.1-2.el8                               appstream   110 k
 gitk                        noarch   2.31.1-2.el8                               appstream   208 k
 gitweb                      noarch   2.31.1-2.el8                               appstream   188 k

Step 2: Restart the Jenkins services by using the below command

 [root@linuxhelp ~] # systemctl restart jenkins.service 

Step 3 Go to the browser and login Jenkins server as shown in the below image

Step 4: Once Login, Select the new item

Step 5: Create a name for the project then select freedata-style as shown in the below image Step 6: Select Git and paste the link in source code management as shown in the below image

Step 7: After creating project, click on BULID Now as shown in the below image

Snap 8: The build is successfully completed. Now you can see on console output as shown in the below image

Step 9: Now move to the Jenkins default Workspace location to see clone project on terminal by using the below command

[root@linuxhelp ~]# cd /var/lib/jenkins/workspace/

Step 10: Now list the workspace using the below command

[root@linuxhelp workspace]# ls -la
total 8
drwxr-xr-x.  3 jenkins jenkins   20 Jul  5 03:28 .
drwxr-xr-x. 14 jenkins jenkins 4096 Jul  5 03:34 ..
drwxr-xr-x. 38 jenkins jenkins 4096 Jul  5 03:34 gitlab

Step 11: Change the location to the GitLab directory by using below command

[root@linuxhelp workspace]# cd gitlab/

Step 12: Now list to check the project clone files by using the below command

[root@linuxhelp gitlab]# ls -la
total 2820
drwxr-xr-x. 38 jenkins jenkins    4096 Jul  5 03:34 .
drwxr-xr-x.  3 jenkins jenkins      20 Jul  5 03:28 ..
drwxr-xr-x. 22 jenkins jenkins    4096 Jul  5 03:33 app
-rw-r--r--.  1 jenkins jenkins    1091 Jul  5 03:33 babel.config.js
drwxr-xr-x.  2 jenkins jenkins    4096 Jul  5 03:33 bin
-rw-r--r--.  1 jenkins jenkins     651 Jul  5 03:33 .browserslistrc
drwxr-xr-x.  2 jenkins jenkins      22 Jul  5 03:33 builds

-rw-r--r--.  1 jenkins jenkins 1827293 Jul  5 03:33 CHANGELOG.md
drwxr-xr-x.  2 jenkins jenkins     104 Jul  5 03:33 changelogs
-rw-r--r--.  1 jenkins jenkins     463 Jul  5 03:33 .codeclimate.yml
drwxr-xr-x. 14 jenkins jenkins    4096 Jul  5 03:33 config
-rw-r--r--.  1 jenkins jenkins     357 Jul  5 03:33 config.ru
-rw-r--r--.  1 jenkins jenkins    5395 Jul  5 03:33 CONTRIBUTING.md
-rw-r--r--.  1 jenkins jenkins     439 Jul  5 03:33 crowdin.yml
-rw-r--r--.  1 jenkins jenkins       6 Jul  5 03:33 .ruby-version
drwxr-xr-x. 12 jenkins jenkins    4096 Jul  5 03:33 scripts
-rw-r--r--.  1 jenkins jenkins     269 Jul  5 03:33 security.txt
drwxr-xr-x.  8 jenkins jenkins     144 Jul  5 03:33 shared
drwxr-xr-x.  2 jenkins jenkins      46 Jul  5 03:33 sidekiq_cluster
-rw-r--r--.  1 jenkins jenkins     397 Jul  5 03:33 .solargraph.yml.example
drwxr-xr-x. 50 jenkins jenkins    4096 Jul  5 03:34 spec

drwxr-xr-x.  3 jenkins jenkins      75 Jul  5 03:34 storybook
-rw-r--r--.  1 jenkins jenkins     400 Jul  5 03:33 .data-stylelintrc
-rw-r--r--.  1 jenkins jenkins     451 Jul  5 03:33 .test_license_encryption_key.pub
-rw-r--r--.  1 jenkins jenkins    1915 Jul  5 03:34 tests.yml
drwxr-xr-x.  2 jenkins jenkins      27 Jul  5 03:33 .theia
drwxr-xr-x.  7 jenkins jenkins     115 Jul  5 03:34 tmp
drwxr-xr-x. 12 jenkins jenkins     245 Jul  5 03:34 tooling
-rw-r--r--.  1 jenkins jenkins     258 Jul  5 03:33 .vale.ini
drwxr-xr-x. 16 jenkins jenkins    4096 Jul  5 03:34 vendor
-rw-r--r--.  1 jenkins jenkins      10 Jul  5 03:33 VERSION

drwxr-xr-x.  8 jenkins jenkins    4096 Jul  5 03:34 workhorse
-rw-r--r--.  1 jenkins jenkins    1229 Jul  5 03:33 .yamllint
-rw-r--r--.  1 jenkins jenkins  608865 Jul  5 03:34 yarn.lock

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to Integrate GitLab with Jenkins. Your feedback is much welcome.

FAQ
Q
Can Jenkins be complicated?
A
Jenkins instances are usually too complex.
Q
Why doesn't Jenkins work?
A
Poor visibility into Jenkins installs and projects creates chaos, can disrupt work, and increases risk.
Q
Is Jenkins self-hosted?
A
Jenkins is a self-contained Java-based program, ready to run out-of-the-box, with packages for Windows, Linux, macOS, and other Unix-like operating systems.
Q
Is Jenkins Free for personal use?
A
Jenkins is absolutely free i.e open-source tool and helps in automating all kinds of tasks associated with the building, testing, delivering, and deploying of an application.
Q
What are the advantages of Jenkins?
A
* It is an open-source tool with great community support.
* It is easy to install.
* It has 1000+ plugins to ease your work. ...
* It is free of cost.
* It is built with Java and hence, it is portable to all the major platforms.