Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,031
Community Members
 
Community Events
184
Community Groups

Resolve Jira issues automatically from the commit message

Use the Git commit message to automate your Jira workflow

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 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.)

Resolve Jira issues from the commit message

  1. Create a new Automation for Jira rule and select the "Commit created" trigger from the DevOps trigger category.

    commit-created.png
  2. Add a new Condition.
  3. Select the Advanced compare condition.
    3.1. Enter {{devops.commit.message}} to the First value field.
    3.2. Choose the contains regular expression option from the Condition dropdown.
    3.3. Enter (?si)(\bfix\b|\bfixes\b|\bfixed\b) to the Second value field.


    jira-resolve-issue-automatically-advanced-compare-condition.png


  4. Save and add a "Run Groovy script" action.

    jira-resolve-issue-automatically-run-groovy.png

  5. Add a description that clearly states what this DevOps automation rule will achieve. For example, add "Transition issue to "Done" as committer".
  6. Add this Groovy script:

    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}")
    	}
    }

  7. Name and save your automation rule.

    jira-devops-automation-issue-transition-to-done-from-commit.png

What you need for this DevOps automation rule

  1. Better Commit Policy for Jira
  2. Better DevOps Automation for Jira
  3. Automation for Jira

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! ⬇️

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events