Automatically resolving a Jira issue from the Git (or other VCS) commit message means that the Jira issue mentioned in the commit message is transitioned at push time without manually updating the status in Jira. It's a frequent use case of DevOps automation rules that updates issues accidentally left in "In-progress" status. It takes some administrative burden off of developers and keeps your agile process on track.
For example, if your commit message is
"Fix the SAM-12 bug."
the SAM-12 issue will be automatically transitioned to "Done" status.
Follow the steps below to build your own DevOps automation rule that sends issues to "Done" status with a command in the Git (or other VCS) commit message.
The below rule is implemented with the free Better DevOps Automation for Jira. It's similar to Smart Commits, but more flexible and works for Data Center (Server) customers as well (who tend not to get the best DevOps automation features natively.)
import com.atlassian.jira.component.ComponentAccessor def issueService = ComponentAccessor.issueService if (!issues) { return } def sourceStatusId = jiraHelper.getStatusByName("In Progress").iddef targetStatusId = jiraHelper.getStatusByName("Done").id def author = devops.committerByUsername ?: {throw new IllegalArgumentException("No user found with username \"${devops.commit.username}\"")}() // def author = devops.committerByEmailAddress ?: {throw new IllegalArgumentException("No user found with email address \"${devops.commit.emailAddress}\"")}() // (alternative, see the Smart Value Reference!)issues.forEach { issue -> if (issue.status.id != sourceStatusId) { return } try { def transitionId = jiraHelper.getTransitionByTargetStatus(issue.key, Long.valueOf((String) targetStatusId)).transitionId def validationResult = issueService.validateTransition(author, issue.id, transitionId as int, issueService.newIssueInputParameters()) if (validationResult.isValid()) { def issueResult = issueService.transition(author, validationResult) if (issueResult.issue.status.id == targetStatusId) { auditLog.info("${issue.key} transitioned to <${issueResult.issue.status.name}>") } else { auditLog.error("${issue.key} not transitioned! (check the workflow configuration!)") } } else { (validationResult.errorCollection.errors.collect { "<${it.key}> field error: ${it.value}" } + validationResult.errorCollection.errorMessages).each { auditLog.error(it) } } } catch (Exception e) { auditLog.error(e.message ?: "${e} ${e.stackTrace}") } }
Read more on how these apps work together to create a fully flexible DevOps automation framework (using custom commands) based on Jira!
Did it work for you? Have a tricky use case? Share your questions or thoughts in the comments below! ⬇️
Levente Szabo _Midori_
Digital Marketing and Customer Success
Midori
Budapest
47 accepted answers
0 comments