I’m currently working on a little development VM and want to share some of my insides I gain and how I managed to get things work. The series will start with the tutorial to install Gerrit.
What is Gerrit?
Gerrit provides a powerful server to integrate a code-review process in your git-driven development process. These are the main reasons I picked gerrit:
- Support git as versioning system – awesome
- Integration with buildservers like jenkins to run test automatically and the CI-server is a part of the code review process
- Great Eclipse integration with EGit
All you need is root shell access to your server and a working internet connection (surprise!)
Generate gerrit2 user
First we generate a group gerrit2 and a user gerrit2 with a home directory located at /usr/local/gerrit2
sudo addgroup gerrit2 sudo adduser --system --home /usr/local/gerrit2 --shell /bin/bash --ingroup gerrit2 gerrit2
I use my own MySQL database instead of the integrated h2 database. You have to generate a user gerrit2 too and a database called reviewdb. On the shell you can do this via
mysql --user=root -p
CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'secret'; CREATE DATABASE reviewdb; ALTER DATABASE reviewdb charset=latin1; GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost'; FLUSH PRIVILEGES; exit;
Last thing to do as a root is to generate a default config file for gerrit. When
sudo touch /etc/default/gerritcodereview
and insert with a editor of your choice
Now we log into our gerrit2 user and install gerrit.
sudo su gerrit2 cd ~ wget http://gerrit.googlecode.com/files/gerrit-2.4.2.war java -jar gerrit-2.4.2.war init -d /usr/local/gerrit2
The address may have altered, so check that.
Fill out everything for your needs. The database password is your secret. Check that everything works b starting gerrit with
cd ~/bin ./gerrit.sh start ./gerrit.sh stop
When everything worked fine, you can updated your init.d to start gerrit automatically on startup. You do this by the following commands.
sudo ln -snf /usr/local/gerrit2/bin/gerrit.sh /etc/init.d/gerrit sudo update-rc.d gerrit defaults
Now your gerrit sever starts each time your machine starts.
I made some errors during the installation which almost drove me crazy.
Authentication via OpenID – Register new Email
It’s great that you can access the gerrit server with OpenID. However if you have another email on your OpenID account (like *@gmail) than you have on your ssh-key (like *@your-company.com) than you must register a new Email on your account. That does only work if your smtp-server is correctly configured.
By default gerrit uses „user@hostname“ as sender. Well for me it was „gerrit@server“ which isn’t a valid emailadress. You can configure your user in the user-section of gerrit.
[user] name = Your name email = firstname.lastname@example.org