Gerrit has a plugin that lets you publish certain Gerrit events to a Slack channel. For more information, see Gerrit’s Slack Integration Plugin documentation.
Install the Gerrit’s Slack Integration Plugin and do the following to publish Gerrit events to a Slack channel:
- Create a Slack App and Webhook URL
- Configure the Slack Integration Gerrit Plugin with the Webhook URL
Let us go through these procedures step-by-step.
Create a Slack App and Webhook URL
Log on to your Slack account. Skip this step if you are logged on already.
Create a Slack App. Skip this step if you already have an app and want to use that to integrate with Gerrit.
Go to the Slack Apps List page and click the Gerrit app.
Select Basic Information from the Settings pane on the left. Click Add Features and Functionality to expand the pane.
Click Incoming Webhooks.
Click the Activate Incoming Webhooks toggle button to turn it on.
Click Add New Webhook to Workspace.
Select the Slack channel where you want your Gerrit notifications posted and click Allow.
A success message appears in your Slack channel.
You have now configured the Webhook URL and this URL is bound to your Slack channel. Gerrit event data posted to this Webhook URL posts a message to the Slack channel.
The Webhook URL for this Slack channel and a sample CURL request to post data to the Webhook URL can be found at the bottom of the page. Keep this Webhook URL handy for later use when you in Gerrit. You can use the CURL command on your CLI to verify that the Webhook URL is indeed emptying itself on the configured Slack channel.
Configure the Slack Integration Gerrit Plugin
The Gerrit’s Slack Integration Plugin is configured via a Gerrit project-specific configuration file. In other words, you must add the Slack channel’s name, Webhook URL, and so on to this configuration file, which is the Gerrit project’s
project.config file on the
refs/meta/config branch of the project.
Here’s a sample
[plugin "slack-integration"] channel = gerrit-post-hackathon-test enabled = true publish-on-patch-set-created = true webhookurl = https://hooks.slack.com/services/T02GN6UQX/B020ZN6/vMrGO
This sample configuration sends notifications for Gerrit events such as
Review comment add (including
Reviewer add, and
Now, if you create a review in this repository, we should see a message from Gerrit in the Slack channel.
Points to Consider
ignore: A dotall enabled regular expression pattern—when matches against a commit message—prevents the publishing of
patchset createdevent’s messages.
ignore-wip-patch-set: Can be set to
trueto prevent Slack notifications regarding a
ignore-comment-author: Regular expression pattern—when matches against the comment author username—prevents the publishing of
comment addedevent’s messages.
publish-on-reviewer-added: Set to
falseto prevent a notification when a reviewer is added to a review.
- Sometimes, it may take time for the Gerrit configuration changes to be applied to the repository. In such a case, force-refresh the repository. For example, here’s a CURL request to force-refresh a repository with
reps1022as its repository ID in TeamForge:
curl -k -X GET https://gerrit.collab.net/api/refresh/repositories/reps1022
The CURL option
-k is added to avoid SSL error. If not CURL, just opening the above repository URL in a browser’s address bar can refresh the repository. Opening the repository URL in a browser is the easiest way and if you are using Gerrit over the browser, you can avoid the SSL error too.