Welcome to the 5th part of our DevOps automation tutorial series! From this part, you can learn how you can send Git commit message and other commit details automatically as a Slack notification.
Check out the previous Jira DevOps automation tutorials or read a summary of the Better DevOps Automation features. These include triggering a Bamboo build, a Jenkins job or a TeamCity build automatically on commit and more.
Send a Slack message on Git commit
Sending a message to your team's Slack channel about a new change pushed to the central repository keeps them up-to-date on developments. Instant messaging is a key component of a DevOps strategy, as it helps achieve shared understanding and cultivates open communications. The way to send an instant Slack message on new Git commits is best implemented with an automation solution.
The below example will walk through the configuration of a Jira automation rule for messaging a Slack channel when a commit is accepted to the repository. The rule is using some enhanced DevOps triggers provided by the free Better DevOps Automation for Jira app.
What components are used?
The Better DevOps Automation for Jira (a free app) adds development-related triggers to Automation for Jira Data Center (+ Server). These DevOps triggers can be used together with the built-in Automation for Jira actions to implement a custom DevOps workflow that fits your team's needs. If you are new to Better DevOps Automation, read our comprehensive introductory blog to learn more about automating DevOps actions on Jira Data Center (and Jira Server) deployments.
Video tutorial: Automatic Slack message on Git commit
Do you prefer a tutorial video? Watch how to create an automation rule for sending a Slack message on Git commit!
Tutorial: Automating a Slack message on Git commit
Follow the steps below to create a Jira automation rule for sending Git commit information as a Slack message. This rule will also contain a condition check to validate if the pushed changes contain actual code changes, not just a new branch or tag. Let's get started!
-
Start creating a new Automation for Jira rule and select Changeset accepted trigger from the DevOps trigger category!
-
Select the Advanced compare condition.
- Type {{devops.changeset.commits.size}} to the First value field.
- Choose the does not equal option from the Condition dropdown.
- Enter "0" to the Second value field.
-
Select the Send Slack message action!
-
Supply your Slack Webhook URL.
(Watch the tutorial above if unsure where to find your Slack Webhook URL.)
-
Add your Slack message in the Message field.
Here you can use the DevOps smart values that the Changeset accepted trigger makes available for you. You can also use the Slack markdown syntax.
For simplicity, we created a compact message template that contains all important Git commit detail together with the changed files and linked Jira issues. You can use it as-is for your automation rule (just click the copy icon in the upper-right corner and paste it into the Message field):
_[DEVOPS] {{devops.changeset.commits.size}} new commit{{#devops.changeset.commits}}{{^first}}{{#last}}s{{/}}{{/}}{{/}}{{^devops.changeset.commits}}s{{/}} in {{devops.changeset.repositoryId}}_ {{#issues.size}} *{{issues.size}} issue{{#issues}}{{^first}}{{#last}}s{{/}}{{/}}{{/}}* linked: {{/}} {{^issues.size}} No issues linked. {{/}} {{#issues}} <{{url}}|{{key}}> {{summary}} {{/}} {{#devops.changeset.commits}} ————— Commit: *#{{id}}* · Branch: *{{branch}}* · Author: *{{author}}* >{{message.replace("\n","\n>")}} *{{files.size}} file{{#files}}{{^first}}{{#last}}s{{/}}{{/}}{{/}}{{^files}}s{{/}}* changed: {{#files}} `{{action.label}}` {{path}} {{/}} {{/}}
-
Give your Slack message automation rule a name and turn it on!
Speed up the flow of information within your team with this simple but powerful Jira DevOps automation rule for sending Slack messages on Git commit details.
Are you ready to give it a try? Start here: