CI/CD with Jenkins – Part 2: Install and Configure Gitlab

What is GitLab?

GitLab is a system for managing Git repositories. It’s written in Ruby and allows you to deploy meaningful version control for your code easily. The core function is similar to GitHub and Bitbucket that provides remote access to the code repository. it provides two variant production Community Edition and Enterprise Edition. In this blog, we are gonna use Community Edition.

Download and Install Gitlab

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-12.4.2-ce.0.el6.x86_64.rpm

Install Gitlab

rpm -i gitlab-ce-12.4.2-ce.0.el6.x86_64.rpm

Change gitlab settings

vim /etc/gitlab/gitlab.rb

Update external URL

external_url 'http://192.168.0.104'

Reload config file and restart Gitlab

gitlab-ctl reconfigure
gitlab-ctl restart

Set up Password
Once started, the home page will appear and ask you to set up password.

Create user, Group and Project


Create Group

Input the info

Create user
It has two types of access level: Regular and Admin
Regular: only have permission to their group and projects.
Admin: can do everything.

Set up Password, click the Edit button to set up password.

add user to group and assign role permission to user

Integrate Jenkins with Gitlab


Jenkins needs to communicate with Gitlab to download or upload, we can use SSH to login to avoid to expose your account.

Perform the following command on your Jenkins server and it will generate the private and public key, which are located in your home folder.

[root@jenkins .ssh]# ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Z4IYMbPGRMjVotCXmVBQLug9nUP6RBBEU7+sEngES9Q root@jenkins
The key's randomart image is:
+---[RSA 4096]----+
|.**#%*           |
|o.*EO=o          |
|.o.+*+ .         |
|. =o=oo..        |
| o *.=.oS o      |
|  . = o  +       |
|   . o           |
|    .            |
|                 |
+----[SHA256]-----+

Add Public key to Jenkins.

Navigate to User Settings-> SSH keys.

add private key in Jenkins, It’s a best practice to use a none-root id.


Conclusion


That’s it, we have successfully deployed the Gitlab server and configured some basic settings – creating user, groups, setting up password, assigning the permission. we have generated pub and private key on Jenkins server and configured it communicating with Jenkins by using SSH.

Leave a Reply

Your email address will not be published. Required fields are marked *