One common goal of software is to automate repetitive tasks. Automation can increase complexity but it can also significantly reduce maintenance and development costs. This is probably the main reason why automation is the cornerstone of common modern Software Engineering practices such as Continuous Testing, Integration and Delivery. Continuous Testing is based upon automating tests, Continuous Integration upon automating the build process and Continuous Delivery upon automating the whole Software Delivery pipeline.
At Infobip, we track changes to services with project version management in JIRA and use Stash for version control. In the beginning, each version was created manually, usually just before deployment. This was a repetitive task that included the manual inspection of commits in version control, creating version in JIRA and linking issues to the version. This was a clear opportunity for automation!
Analyze your workflow
In order to automate this process we need to analyze the manual steps and detect common patterns. For demonstration purposes, let’s assume that we have a Java based project that uses Maven. Commit log after a release might look something like this:
The first and last commit are release commits which contain the version number. Commits in between release commits contain issue keys in their messages (which the Stash itself marks in Issues tab). A user that wants to create a version in JIRA will create a new version with value 1.1.0 and link issues MTP-1, MTP-2 and MTP-3 to the version resulting in:
All the information required to detect the release event, version number and issues in the version can be found in commit messages. This pattern logic can be extracted into an algorithm, which does upon commit:
1. If the commit message doesn’t match the release commit pattern there is no release.
2. Extract the version from the initial commit message.
3. For each commit after the initial one do the following: a. If the commit message doesn’t match the release commit pattern stop b. Extract issue keys
4. Create a version in JIRA with value of the extracted version.
5. Link the extracted issues to the created version.
JIRA version generator
JIRA version generator is a free, open source Stash hook plugin which uses the JIRA REST API to automate the previously described algorithm with some additional features to fine tune the automation process.
Currently, to install the plugin you need to download the plugin jar from Maven Central and install it on your Stash instance. Hopefully, one day we will make the plugin available on the official Atlassian plugin marketplace so the installation process can be more transparent to the user.
After installation, the plugin needs to be activated per repository. Upon activation, the popup settings window will look like this:
The only required parameter in the settings is the JIRA project key parameter which should be self-explanatory.
The Jira version prefix parameter defines a prefix that will be applied to each version generated on JIRA. This can be handy if you have one JIRA project and more multiple artifacts/repositories for that project.
Release commit version pattern is the last parameter that can be used to define the regex used for capturing the version commit pattern. The default value uses the standard Maven Release Plugin pattern with the assumption that the project has the same name as the artifact.
Every time you realize that the work you are currently doing is repetitive and simple, consider how it could be automated to ease and streamline the workload.
JIRA version generator is an example of how this can be done for one small part of the development process. Since the installation, JIRA Version Generator has helped multiple teams reduce some of the tedious work during the release and deploy processes, including the teams which are not using Maven or Java.
By Lovro Pandzic – Software Engineer / Team Leader