Skip to content

Gerrit Installation

doronshai edited this page Nov 11, 2015 · 8 revisions

Main flow is described here - https://gerrit-review.googlesource.com/Documentation/install.html

example of configuration - http://mageconfig.blogspot.co.uk/2014/06/configure-gitgerrit-with-open-ldap-for.html

mysql Installation

login with with root Install mysql-server if missing Using this guide - https://devops.profitbricks.com/tutorials/install-mysql-on-centos-7/ Execute this commands (change password to whatever you want...)

  mysql

  CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'password';
  CREATE DATABASE reviewdb;
  GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost';
  FLUSH PRIVILEGES;

Test that you can login with the following command (type the password that you defined before)

  mysql -u gerrit2 -p
Create User and gerrit folder

login with root

  mkdir -p /opt/gerrit2
  adduser gerrit2
  su gerrit2
  cd /home/gerrit2
  su -
  chown gerrit2 /opt/gerrit2/
Gerrit Site Initialization

login with gerrit2 and execute:

  java -jar gerrit.war init -d /opt/gerrit2

Example of such installation:

  *** Git Repositories
  ***
  Location of Git repositories [git]:
  *** SQL Database
  ***
  Database server type [mysql]:
  Server hostname [localhost]:
  Server port [default]:
  Database name [reviewdb]:
  Database username [gerrit2]:
  Change gerrit2's password [y/N]? y
  gerrit2's password :
  confirm password :
  *** Index
  ***
  Type [LUCENE/?]:
  *** User Authentication
  ***
  Authentication method [LDAP/?]:
  LDAP server [ldap://111.222.333.444]:
  LDAP username [CN=User Name,OU=Group,DC=company,DC=local]:
  Account BaseDN [dc=company,dc=local]:
  Group BaseDN [ou=Groups,dc=company,dc=local]:
  *** Review Labels
  ***
  Install Verified label [y/N]? y
  *** Email Delivery
  ***
  SMTP server hostname [smtp.company.local]:
  SMTP server port [(default)]:
  SMTP encryption [NONE/?]:
  SMTP username [?]:
  Change ?'s password [y/N]?
  *** Container Process
  ***
  Run as [gerrit2]:
  Java runtime [/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85.x86_64/jre]:
  Upgrade /opt/gerrit2/bin/gerrit.war [Y/n]?
  Copying gerrit.war to /opt/gerrit2/bin/gerrit.war
  *** SSH Daemon
  ***
  Listen on address [*]:
  Listen on port [29418]:
  *** HTTP Daemon
  ***
  Behind reverse proxy [y/N]?
  Use SSL (https://) [y/N]?
  Listen on address [*]:
  Listen on port [8080]:
  Canonical URL [http://dev-gerrit.company.local:8080/]:
  *** Plugins
  ***
  Installing plugins.
  Install plugin reviewnotes version v2.11.2 [y/N]?
  Install plugin replication version v2.11.2 [y/N]?
  Install plugin download-commands version v2.11.2 [y/N]?
  Install plugin singleusergroup version v2.11.2 [y/N]?
  Install plugin commit-message-length-validator version v2.11.2 [y/N]?
  Initializing plugins.
  No plugins found with init steps.
  Initialized /opt/gerrit2

After initialization is done do:

  cd /opt/gerrit2/etc
  chmod 600 *config

Add the required fields of LDAP to the gerrit.config: (the password is stored under secure.config and is set also in the initialization script that you just did

  [ldap]
  server = ldap://111.222.333.444
  username = CN=User Name,OU=Group,DC=company,DC=local
  accountBase = dc=company,dc=local
  groupBase = ou=Groups,dc=company,dc=local
  referral = follow
  groupMemberPattern = (&(objectClass=group)(member=${dn}))
  accountFullName = cn
  accountMemberField = memberOf
  accountEmailAddress = mail
  sslVerify = false
  accountScope = subtree
  accountPattern = (&(objectClass=person)(sAMAccountName=${username}))
Start gerrit
  time /opt/gerrit2/bin/gerrit.sh restart
Tail the error_log
  tail -f /opt/gerrit2/logs/error_log
Download, configure and Enable the download commands plugin

open gerrit.config and add these lines

  [download]
    command = checkout
    command = cherry_pick
    command = pull
    command = format_patch
    command = repo_download
    scheme = ssh
    scheme = http
    scheme = anon_http
    scheme = anon_git
    scheme = repo_download

download the binary jar package download-commands plugin from here (Binaries of more plugins are listed [here] (http://gerritcodereview-plugins.storage.googleapis.com/index.html)

put this jar file under the plugin folder

If you still do not see these commands in the UI - Clean the cache and it will solve it

Others

Gerrit with Jenkins: installation and configuration
Migrate a remote Git repository to a new Gerrit project
Migrating a Gerrit project into a different instance of Gerrit
gerrit with jenkins : installation and configuration
Gerrit Admin Console Example of how to Query gerrrit reviewdb