Skip to content

Gerrit integration (deprecated)

Fred G edited this page Nov 21, 2024 · 2 revisions

Important

The Gerrit integration for Jenkins has been deprecated for the CI instances hosted at the Eclipse Foundation in favor of GitHub or GitLab integration.

Gerrit Trigger Plugin

You may use the Jenkins Gerrit Trigger Plugin to run a Jenkins job to verify each new patch set uploaded to Gerrit for code review. Jenkins (named "CI Bot") will then also vote on these changes using the "Verify" voting category.

Gerrit reviewer

Gerrit vote

Below, the configuration sections for the Git plugin and the Gerrit trigger plugin of the verification job used by the EGit project may serve as an example.

General configuration settings

  1. Check "This project is parameterized". Click the "Add" button and select "String Parameter". Set the parameter "Name" to GERRIT_REFSPEC and "Default Value" to refs/heads/master.

Gerrit refspec parameter

Configuration of Source Code Management

  1. Under "Source Code Management" select Git.
  2. Under "Repositories", click on "Advanced" and change the "Refspec" to ${GERRIT_REFSPEC}.
  3. Under "Additional Behaviours", add "Strategy for choosing what to build" and select "Gerrit Trigger" as a strategy.

Jenkins Gerrit git config

Note that the section "Branches to build" won't be used and may be deleted.

Configuration of Build Triggers

  1. Under "Build Triggers", select "Gerrit event".

Gerrit trigger config

  1. Under "Trigger on", click on "Add" and select at least "Patchset Created". This will configure the job to run on each new patchset. You can also add additional trigger, like "Comment Added Contains Regular Expression". In the example below, a build will be triggered for the latest patch set if the comment is exactly "CI Bot, run a build please".

Gerrit trigger events

  1. Finally, configure at least one "Gerrit Project". The pattern is the name of project (i.e. if your repository is git.eclipse.org/<xx>/<yy>.git, then fill the pattern xx/yy). The "Branches" section is the list of branch to listen for events as configured above. Generally, you want one, named "master" to build patches submitted for the master branche, or ** to build patches submitted to each and every branches. Set the type to "Path".

Gerrit trigger project

Configuration of the build action

Under "Build" click the "Add a build step" button, and select the appropriate action. The actual action depends on what you want Jenkins to do. A typical example, for projects built with Maven, is to select "Invoke Maven 3" and set "Maven 3" to apache-maven-latest and "Goals" to clean verify.

Declarative pipeline example

Please note, the pipeline needs to run once to set parameters and triggers.

pipeline {
  agent any
 
  parameters {
    string(name: 'GERRIT_REFSPEC', defaultValue: 'refs/heads/master', description: 'Build master if triggered manually', trim: true)
  }
 
  triggers {
    gerrit customUrl: '', 
      gerritProjects: [[branches: [[compareType: 'PLAIN', pattern: 'master']],
      compareType: 'PLAIN',
      disableStrictForbiddenFileVerification: false,
      pattern: 'jgit/jgit']],
      serverName: 'Eclipse Gerrit',
      triggerOnEvents: [patchsetCreated()]
  }
 
  stages {
    stage('Main') {
      steps {
        checkout scmGit(branches: [[name: '*/master']],
          extensions: [[$class: 'BuildChooserSetting',
          buildChooser: [$class: 'GerritTriggerBuildChooser']]],
          userRemoteConfigs: [[name: 'origin', refspec: '$GERRIT_REFSPEC', url: 'https://git.eclipse.org/r/jgit/jgit.git']])
        sh 'hostname'
      }
    }
  }
}