🛡️ Midori is now SOC 2 compliant! Learn more →

Smart Commit examples to use with Git and Automation for Jira

Jira smart values in automation rules

A selection of smart values make Jira issue details readily available for Automation for Jira rules. They enable customizing automation actions to be useful for your team and your customers.

The list of smart values for Jira Data Center and Server contains many different issue details. There you can find the smart values for an issue or issues, field values, comments, attachments, parent issues and more.

In contrary, there are no smart values for development out of the box! For example, you can't access Git commits (plus Subversion commits and Mercurial commits), tags, branches, pull requests, builds and deployments in automation rules. Atlassian provides those only for Jira Cloud.

In this article, we offer a practical approach to fill this gap. Our approach enables automations in software development projects also on self-hosted Jira deployments (both Data Center and Server).

DevOps smart values for Jira Server

The so-called DevOps smart values are the subset of Jira smart values that are specifically designed for software development work and are relevant mostly for software teams.

For Jira Data Center and Jira Server deployments, DevOps smart values are provided by the free Better DevOps Automation app.

The app adds DevOps automation triggers and DevOps automations actions to those offered by Automation for Jira out of the box. Each DevOps trigger makes relevant smart values available, related to commits, changesets, committer users, branches and more.

Get inspired by the below examples of how you can use these in DevOps automation rules!

The most popular DevOps smart values

1. The developer: {{devops.commit.author}}

This smart value represents the user who created the commit in the Version Control System. This is a valid Jira user account looked up either by the Git username or by the Git email address. (It works identically for Subversion and Mercurial, too!)

2. The complete changeset: {{devops.changeset}}

This DevOps smart value gives you access to a vast array of details about the complete changeset. A changeset is a set of changes pushed to the repository in one go, therefore it can contain multiple commits, tags, branches, etc.

Through nested smart values, you can access:

  • The repository ID
  • The VCS type (Git, SVN, Hg)
  • The tags created by the change
  • The branches created by the change
  • The list of the commits created by the change with further details:
    • Commit ID
    • Branch
    • Commit message
    • The list of the changed files (path, operation, etc.)
  • ...and many more!

3. The commit: {{devops.commit}}

This smart value provides the details of an individual commit. This is the smallest and possibly the most important part of a change.

By nested smart values you can get all the commit details, like:

  • The username of the committer: {{devops.commit.username}}
  • The repository ID: {{devops.commit.repositoryId}}
  • The commit ID (unique identifier of the commit): {{devops.commit.id}}
  • Whether the commit is a merge commit or not: {devops.commit.isMerge}}
  • The branch name: {{devops.commit.branch}}
  • The commit message: {{devops.commit.message}}
  • The list of the files changed by the commit. It contains the full path of those plus the operation code: "a" for "added", "d" for "deleted" and "m" for "modified". - {{devops.commit.files}}

Automate your DevOps workflows for free!

Jira smart value examples for automation rules

The goal of Jira smart values is to be versatile and useful in many different automation use cases.

In the case of DevOps smart values, you can use those to include in communications to involved team members in the form of emails or Slack, Zoom, Microsoft Team and other messaging services.

Let's see some working examples! Don't forget, these Jira smart value examples work with Git and any other VCS out there!

How to send an email on commit with details

DevOps smart values used:

  • Commit ID: {{devops.changeset.commits.id}}
  • Branch name: {{devops.changeset.commits.branch}}
  • Author: {{devops.changeset.commits.author}}
  • Commit message: {{devops.changeset.commits.message}}
  • Number of files changed by the commit: {{devops.changeset.commits.files.size}}
  • Full path for each changed file: {{#devops.changeset.commits.files}}{{path}}{{/}}
  • Color code of the operation for each changed file: {{#devops.changeset.files}}{{action.color}}{{/}}
  • Textual label of the operation for each changed file: {{#devops.changeset.files}}{{action.label}}{{/}}

In this automation rule, the trigger is Changeset Accepted. The rule will be started when one or more commits are pushed to the repository and get accepted by the Better Commit Policy for Jira app.

The action is "Send email" with a custom email subject and custom email body. The formatting in the body is defined by standard HTML tags. The DevOps smart values are marked and numbered on the below image, so you can follow their explanation.

Highlighted with red are the DevOps smart values, and with simple bold are the built-in smart values.

Explanation:

  1. The first one in this example is the commit ID, which can be referenced as {{id}}. This will give back the unique hash identifier of each commit.
  2. This smart value will be replaced by the branch name the commit was made on.
  3. Author is the user who made the commit. His username and email address will both be displayed.
  4. By placing the {{message}} smart value here, the text of the commit message will be displayed.
  5. This will return the number of files changed by commits in the changeset.
  6. The {{action.color}} smart value encodes a color for each file operation. As you can see, you can use it to specify the color of the style attribute of the file operation label.
  7. {{action.label}} tells you what file operation happened: deletion, addition or modification.
  8. Finally, {{path}} smart value displays the full file path of the changed files.

Notice that:

  • A few built-in smart values are also used: Jira project, assignee or the Jira issues linked to the changeset. These can be freely mixed with the DevOps smart values.
  • There are list type smart values used, e.g. {{#devops.changeset.commits}}. Lists can contain multiple items over which you can iterate with the {{#devops.changeset.commits}} syntax (note the hash mark!). To access a property of an item within iteration, it's enough the use the property name: {{message}} instead of {{#devops.changeset.commits.message}}.

This is the email result, that is sent out automatically when a changeset is accepted:

How to send a Slack notification when a new branch is created

DevOps smart values used:

  • Committer user (who created the branch): {{devops.initiator}}
  • Repository ID: {{devops.changeset.repositoryId}}
  • Branch name: {{devops.branch}}

To send out a Slack message when a new branch is created, you need to use the Branch Created DevOps automation trigger, that listens for new branches.

The action is sending a short Slack message with the new branch name, who created it and in which repository.

Explanation:

  1. {{devops.initiator}} smart value gives us the user who created the new branch, or more precisely, who started the automation.
  2. To display the ID of the repository in our Slack message, we can use the {{devops.changeset.repositoryId}} smart value in the body of the message.
  3. Finally, to render the name of the new branch, just use {{devops.branch}}, which will be replaced by the name of the new branch.

This is the Slack message result that is sent out automatically when a new branch is created:

Where else would you use your DevOps Smart Values?

These were samples of popular DevOps smart value use cases, but every team and DevOps workflow is different.

Let us know where would you use DevOps smart values! Get in touch now and ask, so we can help you implement the DevOps automation rule exactly how you need it!

Automate with DevOps smart values!

 

Be the first to hear about the Midori news, Jira, Confluence, Bitbucket guides, and productivity tips that accelerate your team.

Subscribe now