The lines that the user needs to enter or customize will be highlighted in this tutorial! The rest should mostly be copy-and-pastable.
Gerrit is a code review tool that allows developers to push code to an authoritative repository where it can be looked over before being pushed into the production. The application is very synchronized with git. Because of its utility, there are a variety of ways to build out a strong and secure gerrit platform, including using MySQL or Postgres instead of the default H2 database, configuring gerrit behind another webserver, and customizing the authentication used to login (the default is open_id).
This tutorial will cover a simple gerrit explanation that allows you to just get gerrit up and running as quickly as possible on a cloud server.
Before beginning with installing gerrit, we need to be sure that git is installed and set up on our server. If, by any chance, it is not already installed on your cloud server, you can get it quickly through apt-get:
sudo apt-get install git
In order to work, gerrit requires Java to be installed on the server.
You can check if Java is already installed easily:
If it’s not, you can install it, once again, through apt get:
sudo apt-get install default-jdk
Once Git and Java have been downloaded and installed on our server, we can start to set up gerrit. The program itself is hosted on the Google Code site, but the latest version is 2.7
Download the required war file:
Once downloaded, we need to initialize gerrit. You can do so with the command below.
However, should you be content with the default settings, you can have all of them selected at once with the --batch option. Additionally, while by default, gerrit is set up within the user’s home directory, you can set up the specific directory where the files should be placed by adding a –d to the line.
java -jar gerrit-2.7-rc1.war init --batch -d ~/gerrit_example
If this process is done automatically, the canonical URL, where gerrit can be accessed, will simply be localhost
Once Gerrit has been set up, you can start to access it with your desired user.
Gerrit can be accessed through its canonical URL, visible in the settings and easy to find with the command:
git config -f ~/gerrit_example/etc/gerrit.config gerrit.canonicalWebUrl
The visible result should be something along the lines of:
You can change the gerrit settings in the gerrit.config file.
Be sure to restart gerrit after making changes:
If you see localhost in your canonical URL, you should be able to access gerrit through the server’s IP address.
Upon first login, the page should look like this:
With an OpenID, you should be able to create an account on the server. By default, the first account to be registered becomes the superadmin on the site.
When you begin to create a new user, the screen looks like this:
There are several sections that must be filled in. These include Email, Username, and user's SSH key.
If you enter a new email (rather than the default that populates the field), you can manually add it. However, you will need to confirm it before you can register the user under that email.
There is a large field on that page for the user’s SSH key. You should check if you already have an SSH key set up, and, if so, paste in the public key. If you have an SSH key, you should not create a new one
If you do not have an SSH Key, you can follow the instructions on the site to generate one.
You can check double that your SSH key is working by logging into the gerrit through the Command Line with the username that you created. By default gerrit runs on port 29418.
ssh username@localhost -p 29418
You should see the following text after a successful login.
ssh username@localhost -p 29418 The authenticity of host '[localhost]:29418 ([cannonicalURL]:29418)' can't be established. RSA key fingerprint is 19:73:55:9d:63:8b:c5:6f:cb:ee:4c:51:b4:e6:69:e4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[ocalhost]:29418' (RSA) to the list of known hosts. **** Welcome to Gerrit Code Review **** Hi, you have successfully connected over SSH. Unfortunately, interactive shells are disabled. To clone a hosted Git repository, use: git clone ssh://username @localhost:29418/REPOSITORY_NAME.git Connection to cannonicalURL closed.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.