Thursday, August 23, 2018

How to push a repository from gitlab to Gerrit


Use following steps for move git repository from gitlab to Gerrit:
1) Login with admin role and create the repository in Gerrit using the UI
2) Clone the Gitlab repository using the "--bare" option
git clone -- bare git@repo-url(gitlab repo url)

3) Add the gerrit remote
    cd repo-name.git.
    git remote add gerrit gerrit-repo url.

4) Push all commit, branchs and tags to Gerrit
    get push -all gerrit(use --force if there is any issue related to push)
    get push --all gerrit

5) Remove bare repo directory:
    cd ..
    rm -rf repo-name.git.

Ldap configuration for Gerrit

Use below mentioned configuration in LDAP(Active Directory) authentication for Gerrit.

Prerequisite:

  1. You should have your work LDAP for authentication.
  2. You should aware with Gerrit configuration file(gerrit.config) 
1) Open "gerrit.config" file and add below mentioned configuration:
[auth]
        type = LDAP
        gitBasicAuthPolicy = LDAP
[ldap]
        server = ldap://xxx.OurDomain.com/local
        username = CN=test,OU=users,OU=India,OU=Users,DC=OurDomain, DC=com/local
        accountBase = OU=users,OU=India,OU=Users,DC=OurDomain, DC=com/local
        accountPattern = (&(objectClass=user)(sAMAccountName=${username}))
        accountFullName = displayName
        accountEmailAddress = mail
        groupBase = OU=users,OU=India,OU=Users,DC=OurDomain, DC=com/local

2) Save this file and restart your gerrit server.


Tested above mentioned code with Gerrit 2.15.3 version and it was working fine.


Configure Gerrit git repositories replication using replication plugin


If you want to setup the replication of Gerrit repositories to a remote server like git then use following steps:

Perquisites

Install replication plugin if it is not installed(refer this link "http://gerrit-ur:8080/#/admin/plugins/" for verify replication plugin.


Steps:

1) Add below mentioned configuration in "gerrit.config" file.
[plugins]
        allowRemoteAdmin = true  
 2) Create replication.config file with below mentioned details if not exists.

[remote "gerrit_replication"]

  url = git@git-url:groupName/${name}.git
  push = +refs/heads/*:refs/heads/*
  push = +refs/tags/*:refs/tags/*
  timeout = 300
  threads = 3
  remoteNameStyle = dash
  authGroup = Administrators

3) Restart gerrit server.

4) Use these command if you want to start replication. 
ssh -p 29418 usename@gerrit-server gerrit plugin reload replication 
ssh -p 29418 usename@gerrit-server replication start --wait --all

5) Check replication.log file for replication status.

Install eventlog plugin in Gerrit

If you want to install event log plugin for publishing events to Gerrit trigger.

Use below mentioned steps if you want to install event log plugin.

1) Install event log plugin with below mentioned command:
ssh -p 29418 username@gerrit-server gerrit plugin install -n eventlog.jar \ https://gerrit-ci.gerritforge.com/view/Plugins-stable-2.15/job/plugin-events-log-bazel-stable-2.15/lastSuccessfulBuild/artifact/bazel-genfiles/plugins/events-log/events-log.jar

2) Add below mentioned entry in gerrit.config file.

[hook]
        commit-received
        patchsetCreatedHook

3) Restart gerrit server and check logs.