Gerrit trigger
plugin page: https://plugins.jenkins.io/gerrit-trigger
source: https://github.com/jenkinsci/gerrit-trigger-plugin
Setup in Pipeline configuration
See example of typical configuration below:
Notice that you can add more trigger events beside “Patchset Created”, see complete list below. You can also use this pipeline for more projects by using “Add Project” button.
We don’t want Jenkins to set Code-Review label, only Verified, so we need to configure this via the “Advanced…” options in the configuration: Fill the fields under “Code Review” with zeros.
In order to provide the verification label in gerrit, there has to be the gerrit user dedicated to jenkins with access rights set to set label for the project.
Trigger Events
Draft Published: Sent when a change moves from draft state to new.
Patchset Created: Sent when a new patchset arrives on a change.
Change Merged: Sent when a change is merged on the Gerrit server.
Comment Added: Sent when a comment is added to a change. Which category and value to trigger on can be configured. The available categories can be configured in the server settings for the plugin.
Ref Updated: Sent when a ref is updated on the Gerrit server, i.e. someone pushes code review.
Pipeline steps
setGerritReview: Allows altering the Gerrit review posted at the end of build during the build.
Pipeline trigger parameters
Not all of them has to be set. Accessible as environment variables.
GERRIT_CHANGE_SUBJECT: Parameter name for the commit subject (commit message’s 1st line).
GERRIT_CHANGE_COMMIT_MESSAGE: Parameter name for the full commit message.
GERRIT_BRANCH: Parameter name for the branch.
GERRIT_TOPIC: Parameter name for the topic.
GERRIT_OLD_TOPIC: Parameter name for the old topic (in case of topic was changed).
GERRIT_TOPIC_CHANGER: The name and email of the changer of the topic.
GERRIT_TOPIC_CHANGER_NAME: The name of the changer of the topic.
GERRIT_TOPIC_CHANGER_EMAIL: The email of the changer of the topic.
GERRIT_CHANGE_ID: Parameter name for the change-id.
GERRIT_CHANGE_NUMBER: Parameter name for the change number.
GERRIT_CHANGE_URL: Parameter name for the URL to the change.
GERRIT_PATCHSET_NUMBER: Parameter name for the patch set number.
GERRIT_PATCHSET_REVISION: Parameter name for the patch set revision.
GERRIT_PROJECT: Parameter name for the Gerrit project name.
GERRIT_REFSPEC: Parameter name for the refspec.
GERRIT_CHANGE_ABANDONER: The name and email of the abandoner of the change.
GERRIT_CHANGE_ABANDONER_NAME: The name of the abandoner of the change.
GERRIT_CHANGE_ABANDONER_EMAIL: The email of the abandoner of the change.
GERRIT_CHANGE_OWNER: The name and email of the owner of the change.
GERRIT_CHANGE_OWNER_NAME: The name of the owner of the change.
GERRIT_CHANGE_OWNER_EMAIL: The email of the owner of the change.
GERRIT_CHANGE_RESTORER: The name and email of the restorer of the change.
GERRIT_CHANGE_RESTORER_NAME: The name of the restorer of the change.
GERRIT_CHANGE_RESTORER_EMAIL: The email of the restorer of the change.
GERRIT_PATCHSET_UPLOADER: The name and email of the uploader of the patch-set.
GERRIT_PATCHSET_UPLOADER_NAME: The name of the uploader of the patch-set.
GERRIT_PATCHSET_UPLOADER_EMAIL: The email of the uploader of the patch-set.
GERRIT_EVENT_ACCOUNT: The name and email of the person who triggered the event.
GERRIT_EVENT_ACCOUNT_NAME: The name of the person who triggered the event.
GERRIT_EVENT_ACCOUNT_EMAIL: The email of the person who triggered the event.
GERRIT_REFNAME: The refname in a ref-updated event.
GERRIT_OLDREV: The old revision in a ref-updated event.
GERRIT_NEWREV: The new revision in a ref-updated or change-merged event.
GERRIT_SUBMITTER: The submitter in a ref-updated event.
GERRIT_SUBMITTER_NAME: The name of the submitter in a ref-updated event.
GERRIT_SUBMITTER_EMAIL: The email of the submitter in a ref-updated event.
GERRIT_NAME: The name of the Gerrit instance.
GERRIT_HOST: The host of the Gerrit instance.
GERRIT_PORT: The port number of the Gerrit instance.
GERRIT_SCHEME: The protocol scheme of the Gerrit instance.
GERRIT_VERSION: The version of the Gerrit instance.
GERRIT_EVENT_HASH: A hashcode of the Gerrit event object, to make sure every set of parameters is unique (allowing jenkins to queue duplicate builds).
GERRIT_EVENT_TYPE: The type of the event.
GERRIT_EVENT_COMMENT_TEXT: Comment posted to Gerrit in a comment-added event.
Example of values
Useful code snippets
//def repoUrl = 'ssh://jenkins-builder-amarula@gerrit-review.amarulasolutions.com:29418/aevi-albert/qa-automated-tests'
def repoUrl = "ssh://jenkins-builder-amarula@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"