Gerrit Code Review plugin for Jenkins
- see Jenkins wiki for detailed feature descriptions
- use JIRA to report issues / feature requests
The master branch is the primary development branch for the Gerrit Code Review plugin.
Plugin source code is hosted on GitHub. New feature proposals and bug fix proposals should be submitted as Gerrit changes on GerritHub or as pull requests if you are not familiar with Gerrit Code Review.
Before submitting your contribution, please assure that you've added a test which verifies your change.
$ java -version # Need Java 1.8, earlier versions are unsupported for build
$ mvn -version # Need a modern maven version; maven 3.2.5 and 3.5.0 are known to work
$ mvn clean install
Create a new Multibranch Pipeline
item.
Select Branch Source
of type Gerrit
.
Specify project repository URL, only http
or https
based protocol is
supported at this point, copy the URL from project settings at Gerrit.
Trigger Scan Multibranch Pipeline now
either manually or by external
trigger.
Notice the Changes
tab at the job information, per each review an entry will
be created.
Remote trigger is possible using webhook, URL is
https://jenkins/prefix/gerrit-webhook/
.
Content:
{
"project": {
"name": "project1"
}
}
Example:
$ curl -X POST -d '{"project":{"name":"project1"}}' 'https://jenkins/prefix/gerrit-webhook/'
Configure Gerrit Trigger Plugin normally.
At the job that being triggered, add a parameter with the name of
GERRIT_CREDENTIALS_ID
with default value of a credentials id that can access
Gerrit using RestAPI.
Key | Description |
---|---|
GERRIT_API_URL | Gerrit API URL, onlhy http and https protocols are supported |
GERRIT_CHANGE_URL | Gerrit change URL to parse GERRIT_API_URL out if missing |
GERRIT_API_INSECURE_HTTPS | If set to true certificate validation will be disabled |
GERRIT_CREDENTIALS_ID | Jenkins credentials object id |
GERRIT_PROJECT | Gerrit project name |
BRANCH_NAME | Gerrit reference name nn/nnnn/n |
GERRIT_CHANGE_NUMBER | Gerrit change number |
GERRIT_PATCHSET_NUMBER | Gerrit revision |
GERRIT_CHANGE_PRIVATE_STATE | true if the Gerrit change is private |
GERRIT_CHANGE_WIP_STATE | true if the Gerrit change is WIP |
GERRIT_CHANGE_SUBJECT | Gerrit change headline |
GERRIT_BRANCH | target branch of the Gerrit change |
GERRIT_TOPIC | topic name (if any) of the Gerrit change |
GERRIT_CHANGE_ID | Gerrit change id |
GERRIT_CHANGE_URL | Gerrit change URL |
GERRIT_PATCHSET_REVISION | SHA1 of the Gerrit patch-set |
GERRIT_CHANGE_OWNER | Owner (name ) of the Gerrit change |
GERRIT_CHANGE_OWNER_NAME | Owner name of the Gerrit change |
GERRIT_CHANGE_OWNER_EMAIL | Owner e-mail of the Gerrit change |
GERRIT_PATCHSET_UPLOADER | Uploader (name ) of the Gerrit patch-set |
GERRIT_PATCHSET_UPLOADER_NAME | Uploader name of the Gerrit patch-set |
GERRIT_PATCHSET_UPLOADER_EMAIL | Uploader e-mail of the Gerrit patch-set |
GERRIT_REFNAME | Git ref name of the change/patch-set |
When the Jenkinsfile is discovered through a multi-branch pipeline, the above environment variables related to Gerrit and the associated change/patch-set would be automatically discovered and made available to the pipeline steps.
For the pipeline projects (non-multibranch) the variables would need to be set through an external triggering job (e.g. Gerrit Trigger Plugin).
Gerrit Code Review plugin provides steps for allowing to post the review feedback back to the originating change and adding extra comments to the code that has been built.
Add a review label to the change/patchset that has triggered the multi-branch pipeline job execution.
Parameters:
-
labels
The labels associated to the review, a dictionary, key is label name and value is the score. -
message
Additional message provided as explanation of the the review feedback. Default: ''
Add a review comment to the entire file or a single line.
All the comments added during the pipeline execution are going to be
published upon the execution of the gerritReview
step.
Parameters:
-
path
Relative path of the file to comment. Mandatory. -
line
Line number of where the comment should be added. When not specified the comment apply to the entire file. -
message
Comment message body. Mandatory.
Note: the gerrit DSL helper was removed in 0.3, please use the following.
pipeline {
agent any
stages {
stage('Example') {
steps {
gerritReview labels: [Verified: 0]
echo 'Hello World'
gerritComment path:'path/to/file', line: 10, message: 'invalid syntax'
}
}
}
post {
success { gerritReview labels: [Verified: 1] }
unstable { gerritReview labels: [Verified: 0], message: 'Build is unstable' }
failure { gerritReview labels: [Verified: -1] }
}
}
node {
checkout scm
try {
gerritReview labels: [Verified: 0]
stage('Hello') {
echo 'Hello World'
gerritComment path:'path/to/file', line: 10, message: 'invalid syntax'
}
gerritReview labels: [Verified: 1]
} catch (e) {
gerritReview labels: [Verified: -1]
throw e
}
}