Thursday, June 1, 2017

How does gerrit trigger work on Jenkins

The gerrit trigger works like this:
  1. It connects to the gerrit server using ssh and uses the gerrit stream-events command
  2. It then watches this stream as the data comes in
  3. It will try to match the events to triggers that have defined in your projects
Common issues:
  1. Jenkins user has improper ssh credentials
  2. Jenkins user does not have the stream-events rights
  3. The user public key was not added to gerrit
How to check:
  1. Login as jenkins user, assume username is admin
  2. ssh -p 29418 admin@gerrit_server gerrit stream-events
  3. Push a commit to the server and you should see things on your stream
Problems:
  1. ssh connection failed? setup you ssh key pair
  2. No streaming right? Go to the All-Projects->Access and under Global Capabilities add Stream Events to the Non-Interactive Users group

Gerrit access rights

  1. Create the profile through in Gerrit web interface for your Jenkins user, and set up a SSH key for that user.
  2. Gerrit web interface > Admin > Groups > Non-Interactive Users > Add your jenkins user.
  3. Admin > Projects > ... > Access > Edit
    • Reference: refs/*
      • Read: ALLOW for Non-Interactive Users
    • Reference: refs/heads/*
      • Label Code-Review: -1, +1 for Non-Interactive Users
      • Label Verified: -1, +1 for Non-Interactive Users
IMPORTANT: On Gerrit 2.7+, you also need to grant "Stream Events" capability. Without this, the plugin will not work, will try to connect to Gerrit repeatedly, and will eventually cause OutOfMemoryError on Gerrit.
  1. Gerrit web interface > People > Create New Group : "Event Streaming Users". Add your jenkins user.
  2. Admin > Projects > All-Projects > Access > Edit
    • Global Capabilities
      • Stream Events: ALLOW for Event Streaming Users

1 comment:

  1. This is just copied from stackoverflow...

    ReplyDelete