Wednesday 23 September 2015

Part 7 -- Setup Jenkins and gerrit: Making Jenkins and gerrit aware of each other

Suppose you have a project named "my_product" on gerrit and you want to run sanity tests on it before merging any code there. After-all, you definitely want to make sure that new commit does not break anything.

What about having a capability of running some job (test pipeline) on Jenkins everytime new commit comes on gerrit?

To have this, Jenkins and gerrit should know each other.
  • For running test scripts of project, Jenkins should also be able to clone project from gerrit.
  • Gerrit should have ability to send an event to Jenkins on arrival of new commit. 
  • On other side, Jenkins should have ability to receive those events. 
Connect Jenkins and Gerrit -- Create jenkins user on gerrit:
- Create new OpenId for Jenkins user.
- Go to "http://gerrit1:8080"
- Login with new jenkins openid.
You also have to add jenkins server ssh keys to gerrit account such that Jenkins server can have access to projects.
- Go to terminal of jenkins server. Generate ssh keys (ssh-keygen -t rsa).
- Copy key to /var/lib/jenkins/.ssh/id_rsa.
- Go to "http://gerrit1:8080" jenkins account.
- Settings --> sshkeys. Add key there.
Connect Jenkins and Gerrit -- Give jenkins user administrator rights:
- Login to your admin account.
- Add jenkins user as administrator by going to List Groups --> Administrator.
Connect Jenkins and Gerrit -- Install gerrit Plugin:
First thing which you need to do is to install "gerrit plugin". To do so, follow below steps
  1. Manage Jenkins --> Manage plugins

  2. Go to available tab and filter for "Gerrit Trigger" plugin

  3. Select plugin and click "Install without restart".
  4. You should see something like below

  5. Check "Restart Jenkins when installation complete ...".
Connect Jenkins and Gerrit -- Configure gerrit plugin:
  1. Go to "Manage Jenkins" --> "gerrit trigger"

  2. Click "Add new server"

  3. Provide following information
    Hostname:     Ip address of gerrit server           [10.10.0.19]
    Frontend URL: protocol://ip:port of gerrit server   [https://10.10.0.19:8443/]
    sshproxy:                                           [29418]
    Username:     Name of the gerrit user               [gerrit-settings -> profile -> username]
    Email:        OpenId email used                     [jenkins24434@gmail.com]
    sshkeyfile:                                         /var/lib/jenkins/.ssh/id_rsa
    
  4. Click Test connection. It should show success.


Now you are all set to run a job in response to a commit on gerrit.

No comments:

Post a Comment