Is there a workaround to https://jira.atlassian.com/browse/JRA-24118 ? BTW Please vote!
I need to add a label to some issues based on issue navigator search result. Bulk edit erases old labels and adds new which does not work for me.
Is there coding-free option?
Get Script Runner plugin and execute following Groovy script:
import com.atlassian.jira.web.bean.PagerFilter import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.label.LabelManager import com.atlassian.jira.bc.JiraServiceContextImpl filterId = 10000 labelName = 'Label' cm = ComponentManager.instance labelManager = ComponentManager.getComponentInstanceOfType(LabelManager.class) searchRequestService = cm.searchRequestService searchProvider = cm.searchProvider user = cm.jiraAuthenticationContext.getLoggedInUser() ctx = new JiraServiceContextImpl(user) sr = searchRequestService.getFilter(ctx, filterId) searchResult = searchProvider.search(sr?.getQuery(), user, PagerFilter.unlimitedFilter) searchResult.issues.each{issue -> labelManager.addLabel(user, issue.id, labelName, false) } "Done."
Adapt filterId and labelName to your needs.
Henning
Is this going to send any email notifcations or not? I will it will not send them.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It depends on the last parameter for addLabel(). If it's false like here, no notifications are send. If it's true, notifications are send.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you. Due to the nature of the problem we decided to implement a SMTP filter for changes made by a service account jira user.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the script, Mr Tietgens!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I updated the script from my old answer, there was some html code from the conversion from Atlassian Answers to Community.
Here is a solution using JQL search:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.label.LabelManager
def jqlSearch = "project = ABC"
def labelName = 'Label'
def labelManager = ComponentAccessor.getComponent(LabelManager)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def searchService = ComponentAccessor.getComponent(SearchService)
if (user) {
def parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
searchResult.issues.each{issue ->
labelManager.addLabel(user, issue.id, labelName, false)
}
} else {
return "Invalid JQL $jqlSearch"
}
} else {
Return "No logged in user found!"
}
"Done."
It's typed without without verification, so test first on a staging environment :-)
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, ComponentManager shouldn't be used anymore. Try the new script or try to replace ComponentManager by ComponentAccessor like in the new script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I replaced ComponentManager by ComponentAccessor, but still
Error
startup failed: Script273.groovy: 2: unable to resolve class com.atlassian.jira.ComponentAccessor @ line 2, column 1. import com.atlassian.jira.ComponentAccessor ^ 1 error
when I used JQL 2nd script its
Error
startup failed: Script275.groovy: 23: unexpected token: No logged in user found! @ line 23, column 9. Return "No logged in user found!" ^ 1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, some typing errors and a missing import in the JQL script, here the updated version:
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.label.LabelManager
def jqlSearch = "project = ABC"
def labelName = 'Label'
def labelManager = ComponentAccessor.getComponent(LabelManager)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def searchService = ComponentAccessor.getComponent(SearchService)
if (user) {
def parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
searchResult.issues.each{issue ->
labelManager.addLabel(user, issue.id, labelName, false)
}
} else {
return "Invalid JQL $jqlSearch"
}
} else {
return "No logged in user found!"
}
"Done."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And here the filter id script for current Jira versions:
import com.atlassian.jira.bc.filter.SearchRequestService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.bc.JiraServiceContextImpl
def filterId = 10000
def labelName = 'Label'
def labelManager = ComponentAccessor.getComponent(LabelManager)
def searchRequestService = ComponentAccessor.getComponent(SearchRequestService)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def ctx = new JiraServiceContextImpl(user)
def sr = searchRequestService.getFilter(ctx, filterId)
def searchResult = searchProvider.search(sr?.getQuery(), user, PagerFilter.unlimitedFilter)
searchResult.issues.each{issue ->
labelManager.addLabel(user, issue.id, labelName, false)
}
"Done."
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Love you @Henning Tietgens !
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.
No, this is Groovy not Python.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Henning Thanks for your example. I used it and modified to create a script to remove a single label.
Wanted to post it in case anyone else is looking to bulk rename labels. I'd suggest add new label then remove old.
import com.atlassian.jira.web.bean.PagerFilter import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.label.LabelManager import com.atlassian.jira.bc.JiraServiceContextImpl filterId = 10602 labelName = 'Label' cm = ComponentManager.instance labelManager = ComponentManager.getComponentInstanceOfType(LabelManager.class) searchRequestService = cm.searchRequestService searchProvider = cm.searchProvider user = cm.jiraAuthenticationContext.getLoggedInUser() ctx = new JiraServiceContextImpl(user) sr = searchRequestService.getFilter(ctx, filterId) searchResult = searchProvider.search(sr?.getQuery(), user, PagerFilter.unlimitedFilter) searchResult.issues.each{issue -> labelManager.setLabels(user, issue.id, (labelManager.getLabels(issue.id).collect{l -> l.getLabel()}.minus(labelName)) as Set, false, true) } "Label" + labelName + " removed from issues in filter " + filterId.toString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.