Automatically Update the Assignee of an Issue in Jira

Overview

Automatically update the Assignee field of an issue in Jira with this snippet.

Example

I can use this snippet as part of a larger script, so if an issue isn't updated within seven days, the assignee changes automatically.

Requirements

Jira Jira (7.3 - 7.13)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueInputParametersImpl

// the issue key to update
final String issueKey = "JRA-1"

// the user key of the new assignee
final String newAssigneeId = "admin"

// change to 'true' if you want to send an email if the update is successful
final boolean sendMail = false

def issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey)

assert issue : "Could not find issue with key $issueKey"

def issueInputParameters = new IssueInputParametersImpl()
issueInputParameters.setAssigneeId(newAssigneeId)

def updateValidationResult = issueService.validateUpdate(loggedInUser, issue.id, issueInputParameters)
assert updateValidationResult.isValid() : updateValidationResult.errorCollection

def issueUpdateResult = issueService.update(loggedInUser, updateValidationResult, EventDispatchOption.ISSUE_UPDATED, sendMail)
assert issueUpdateResult.isValid() : issueUpdateResult.errorCollection
Discovered an issue? Report it here

Suggested for you