-
Notifications
You must be signed in to change notification settings - Fork 37
Gerrit integration (deprecated)
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.
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.
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.
- Check "This project is parameterized". Click the "Add" button and select "String Parameter". Set the parameter "Name" to
GERRIT_REFSPEC
and "Default Value" torefs/heads/master
.
- Under "Source Code Management" select Git.
- Under "Repositories", click on "Advanced" and change the "Refspec" to
${GERRIT_REFSPEC}
. - Under "Additional Behaviours", add "Strategy for choosing what to build" and select "Gerrit Trigger" as a strategy.
Note that the section "Branches to build" won't be used and may be deleted.
- Under "Build Triggers", select "Gerrit event".
- 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".
- 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 patternxx/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".
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
.
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'
}
}
}
}