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:
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}") } }
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.
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.
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! ⬇️
Levente Szabo _Midori_
Digital Marketing and Customer Success
Midori
Budapest
48 accepted answers
2 comments