Gerrit (Code Review), GitLab (Replication) Jenkins Integration

DZone 's Guide to

Gerrit (Code Review), GitLab (Replication) Jenkins Integration

Explore a tutorial of integrating Gerrit and Gitlab.

· Integration Zone ·
Free Resource

Upcoming DevOps culture needs the end to end traceability and work done by the automation so when it comes to the code review part, it's still a starting phase of implementation found everywhere.

So, I started exploring how to do the code review from the developer point of view using Gerrit and replicate the same repository to the Gitlab and status events triggers can be shown in Jenkins.

The following are the requirements for the Gerrit installation:

1) Linux Node — I suggest Centos 7

2) Java package 1.8

3) MySQL MariaDB

4) Gerrit stable and latest release packgae from the gerrit mirror.

Installation process

Yum update -y
yum install java-1.8.0-openjdk.x86_64 -y
java -version
Yum install mariadb mariadb-server mysql
systemctl restart mariadb
systemctl status mariadb
systemctl enable mariadb

Once the Mysql service is started succcessfully. Change the root password for root login

Enter current password for root (enter for none): ENTER
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Installing Gerrit and creating a database for gerrit with granting all privileges to the database.

mysql -u root -p
MariaDB> create database gerritdb;
MariaDB> grant all on gerritdb.* to gerrit@localhost identified by 'secret';

Add gerrit user on Centos node to install the gerrit configuration package.

Wget https://gerrit-releases.storage.googleapis.com/gerrit-2.15.5.war

Once the latest version of war is downloaded, extract the war files as follows:

java -jar gerrit.war init -d /home/gerrit/gerrit-2.15

During the installation, the wizard may ask some default options to choose for the requirements based.

Location of Git repositories   [git]: GIT
Database server type           [mysql]: Mysql
Server hostname                [localhost]: Enter
Server port                    [(mysql default)]:Enter 
Database name                  [gerritdb]: Enter
Database username              [gerrit]: Enter
Change gerrit's password       [y/N]? : Enter
Type                           [LUCENE/?]: Enter
Authentication method          [HTTP/?]: ? (Use Devlopment option)
Get username from custom HTTP header [y/N]?  Enter
SSO logout URL                 : Enter
Install Verified label         [y/N]? Enter
SMTP server hostname           [localhost]: Enter
SMTP server port               [(default)]: Enter
SMTP encryption                [NONE/?]: Enter
SMTP username                  : Enter
Run as                         [gerrit]: Enter
Java runtime                   [/usr/java/jdk1.8.0_25/jre]: Enter
Upgrade /home/gerrit2/review_site/bin/gerrit.war [Y/n]? : Y
Copying gerrit.war to /home/gerrit2/review_site/bin/gerrit.war
Listen on address              [*]: Enter
Listen on port                 [29418]: Enter
Behind reverse proxy           [Y/n]? Enter
Proxy uses SSL (https://)      [y/N]? Enter
Subdirectory on proxy server   [/gerrit/]: Enter
Listen on address              [*]: Enter
Listen on port                 [8081]: Enter
Canonical URL                  [http://ganeshbabu.com/gerrit/]: Enter (if you want change the external url you can do it here
Install plugin commit-message-length-validator version v2.9.1 [y/N]? Y
Install plugin download-commands version v2.9.1 [y/N]? Y
Install plugin replication version v2.9.1 [y/N]? Y
Install plugin reviewnotes version v2.9.1 [y/N]? Y
Install plugin singleusergroup version v2.9.1 [y/N]? Y

Once the installation is done, Start the Gerrit service with the below command

Sh /home/gerrit/gerrit-2.15/bin/gerrit.sh start -- stop -- restart

Now go to gerrit Dashboard http://xx.xx.xx.xx:8080

1) Create a user as admin or administrator

Image title

2) Create a Project repository

Image title

3) Clone it into the local machine with hook commit msg

Image title

Image title

4) Do the code changes on the repository branch, and commit and push it to accordingly.

Now, you can go to Gitlab Dashboard and Create a User for Gerrit, or you can use the admin account for the integration of Gerrit with Gitlab for the replication.

5) Y you need to create a replication.config on Gerrit node.

Vim /home/gerrit/etc/replication.config

Image title

a) Project Name should be same as in Gerrit and Gitlab

b) Git repository Url should be mentioned on the replication.config

c) If everything goes fine, you can see the logs under /home/gerrit/logs/replication.log as success.

Image title

Once the replication is started, the code changes can be imported to Gitlab.

So, when it comes to Jenkins integration with Gerrit, it makes sense for complete phase of the solution.

We have many blogs and references for Jenkins to install and configure its basic setup, so I am skipping it here.

Once the installation of Jenkins and Gerrit. We need to install plugins for Gerrit to integrate it with lot many tools like Jenkins, Jira, etc.

Below are the steps and commands to install the plugins on Gerrit.

This is the Gerrit plugins mirror URL. we can find out many plugins based on versions and tools.


ssh -p 29418 admin@gerritserverip gerrit plugin install -n reviewers-review.jar https://gerrit-ci.gerritforge.com/view/Plugins-stable-2.14/job/plugin-reviewers-bazel-stable-2.14/lastSuccessfulBuild/artifact/bazel-genfiles/plugins/reviewers/reviewers.jar

Once the plugin is installed, it can be intracted with defined tools.

Now, we can see the Jenkins Gerrit integration configuration.

So, after installing the Gerrit plugin on Jenkins, manage plugin tab --> go to manage jenkins --> Gerrit icon. and do the below configuration changes.

Image title

And also, we need to enable the API authentication between Jenkins and Gerrit for the automatic build trigger when the user does his changes on the Gerrit server, it will build automatically on Jenkins.

Image title

Make sure it's the same user and password created on Gerrit account DB.

Finally, we come to the end of the integration part of Jenkins and Gerrit.

There are different sets of triggers in the Gerrit use case of Jenkins, so use it accordingly for the best results.

code review ,gerrit ,gitlab ,integration ,jenkins integration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}