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,361,472
Community Members
 
Community Events
168
Community Groups

How to transition a Jira issue on first commit

A Jira issue is often left in "To Do" when developers start working on a task and forget to update the issue. This makes the Scrum board or product roadmap unreliable and can mislead product managers.

You can take this administrative work off of developers' shoulders with automation. Create a Jira automation rule that automatically transitions a Jira issue from "To Do" to "In Progress" on the first commit!

An added bonus: the below automation will perform the issue transition on behalf of the committer, instead of an "automation agent".

Transition a Jira issue on commit

This DevOps automation rule will transition a Jira issue left in "To Do" to "In Progress" when the first commit is created.

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

    commit-created.png
  2. Add a new action "Run Groovy script"

    run-groovy-script-action.png

  3. Add a description that clearly states what this DevOps automation rule will achieve. For example, add "Transition issue to "In Progress" as committer" to the Description field.

  4. Add this Groovy script:
    import com.atlassian.jira.component.ComponentAccessor
    
    def issueService = ComponentAccessor.issueService
    
    if (!issues) {
    	return
    }
    
    def sourceStatusId = jiraHelper.getStatusByName("To Do").iddef targetStatusId = jiraHelper.getStatusByName("In Progress").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}")
    	}
    }

    transition-issue-action.png

  5. Name and save your automation rule.

    save-automation-rule.png

Now if a Jira issue in "To Do" status is mentioned in the commit message, it will be automatically transitioned to "In Progress"! If you look at the History of the issue, you can see that the issue was transitioned by the committer user.

jira-devops-automation-issue-transition-on-commit-annotated.png

                      The mentioned issue was transitioned in the name of the committer user

This transition only happens once, for the first commit that mentions this issue. Also, it only happens between “To Do” and “In Progress” statuses in this exact direction. No “Done” issues will be moved to “In Progress” again.

What you need for this DevOps automation rule

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

Why do I need to install these apps, you wonder? Read more on how these apps work together to create a fully flexible DevOps automation framework based on Jira!

This is way smarter than Smart Commits

This automation rule for transitioning an issue from "To Do" to "In Progress" is just the tip of the iceberg. You can achieve much more with DevOps Automation for Jira!

Discover the Genius Commits and how they compare to Bitbucket Smart Commits!

Genius Commits carry special commands in the commit message. You can trigger any automation action with them, like running a CI/CD build, tests, Slack notifications, Jira issue operations, and much more!

You can even create your custom command or use many built-in commands to trigger the DevOps action you need.

Have questions or a tricky use case? Ask in the comments below! ⬇️

0 comments

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Apps & Integrations

Apps for Confluence you won't want to miss: RSVP for September's Appy Hours

Calling all collaborators and Confluence users! Our Appy Hours event on September 29th features 4 presenters demoing functionality to superpower Confluence. Don't miss learning about these apps i...

123 views 0 9
Read article

Atlassian Community Events