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

How to automatically assign a Jira issue to committer

Assigning a Jira issue automatically is useful when developers pick up work and forget to assign the issue to themselves.

The first commit mentioning a Jira issue is a good DevOps automation trigger to have the robots assign the issue to the committer user.

The below DevOps automation rule example doesn't even require any special parameters or commands. It works with Git and also with many other VCS as well.

If an unassigned Jira issue is mentioned in the commit message, the assignee will be set to the committer user.
Follow these steps to build your DevOps automation rule:

  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 do. For example, add "Automatically set assignee" to the Description field.
  4. Add this Groovy script:

    import com.atlassian.jira.component.ComponentAccessor
    
    def issueService = ComponentAccessor.issueService
    
    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.assignee) {
    		return
    	}
    	try {
    		def issueParams = issueService.newIssueInputParameters()		issueParams.setAssigneeId(author.username)
    
    		def validationResult = issueService.validateUpdate(author, issue.id, issueParams)
    		if (validationResult.isValid()) {
    			def issueResult = issueService.update(author, validationResult)
    			if (issueResult.issue.assignee) {				auditLog.info("${issue.key} assignee updated to <${issueResult.issue.assignee.displayName}>")
    			} else {				auditLog.error("${issue.key} assignee not updated! (check the field and screen 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}")
    	}
    }
  5. Name and save your automation rule.

    automatically-assign-jira-issue-to-committer.png


Now if a Jira issue without an assignee is mentioned in the commit message, it will be automatically assigned to the developer committing changes related to the issue.

Specify a different assignee than the committer

It's also possible that the developer committing the changes wants to set a different user as the assignee. You can create a special command for this use case with the Genius Commits feature of Better DevOps Automation for Jira.

Learn how you can customize the above DevOps automation rule and allow users to specify an assignee in the commit message.

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!

Need help with a tricky use case? Share your questions or thoughts in the comments below! ⬇️

2 comments

Comment

Log in or Sign up to comment
KrithVe January 6, 2023

Good read. I assume these add-ons are for Data Centre and Server edition?

Does this auto assign based on pull request too?

Syed Javeed Ahammad September 14, 2023

Hi @Levente Szabo _Midori_ 

 

How to Auto assign issues to "Assignee" in "JSM" based on Automation with Groovy Scripting

based on Category and Subcategory cascading Field

Example

 if Category ("ABC") and Subcategory ("EFG") Selected then "abc@xyz.com" should add as "Assignee" in Ticket

 

cat.png

TAGS
AUG Leaders

Atlassian Community Events