You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hi!
I am trying to bulk change issue types via groovy. I have been able to do so but only at a single issue, here is the following script:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption def issueManager = ComponentAccessor.issueManager def constantsManager = ComponentAccessor.constantsManager def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser def issueKey = 'xx-xxx' def issue = issueManager.getIssueObject(issueKey) def summary = issue.summary def description = issue.description def sourceIssuetype = issue.getIssueType().getName() def targetIssueType = constantsManager.allIssueTypeObjects.find {it.name == 'Task' } if (sourceIssuetype = 'Bug') { issue.setIssueType(targetIssueType) issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false) }
I am hoping to pass a JQL into the script or a bulk amount of issues to change at once. The UI move is very tedious and often times out for us. Any suggestions?
I see you are using issueManager instead of the new HAPI methods.
Perhaps you don't have access to the recent version of Scriptrunner that includes HAPI.
So if you need to use the native JQL searching capabilities, here is how you could write your script:
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
SearchService searchService = ComponentAccessor.getComponent(SearchService)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def jql = '' //specify your jql here
searchService.parseQuery(currentUser, jql)
def jqlParseResult = searchService.parseQuery(currentUser, jql)
assert jqlParseResult.isValid(), jqlParseResult.errors
searchService.search(currentUser, jqlParseResult.query, PagerFilter.unlimitedFilter).results.each { issue ->
//do your issue operations here
}
But there is a possibility with this code that you will run out of memory if you try to run it on a very large number of issues.
The better approach would be to use a limited-size PageFilter and run this in chunks.
Another couple of caveats:
1) changing the issuetype on an issue is usually not recommended. This will not take care of migrating the issue to the correct workflow for the new issue type and all other scheme-related adjustments like the "move" operation in the UI does. The only place I would allow this is if the 2 issue types share ALL the same configuration: same workflow, same issue configs etc.
I am not aware of any single command that can replicate the move operation.
2) your code was missing a critical step of re-indexing the issue after updating it with the issueManager. Your search results would still be based on the old values. You need to also trigger a re-indexing. If you use IssueSearvice instead of IssueManager, you don't need to worry about the index.
Thanks Peter! I was attempting to use HAPI, but it couldn't find any documentation around updating the issuetype via HAPI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can still use HAPI to apply your JQL then run normal issue update code inside the search even if issue.update{ } doesn't offer a way to update the issue type (for good reason as mentioned above).
Issues.search(jql).each{ issue->
//do issue stuff here, and use issueManager.update
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.