I'm very familiar with adding Post Functions to alter an issue during a transition. The problem is that I can't seem to find a way to remove one particular label during transition to Resolution. I can clear the entire field, but that is not desirable.
I have also tried to create a Condition to prevent Resolution of an issue if the label is present, but this didn't appear to work either. A few comments by Atlassian employees imply that Conditions can't work with the system Labels field.
You could use the Script Runner plugin and the following script for a start.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.label.LabelManager def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser() LabelManager labelManager = ComponentAccessor.getComponent(LabelManager) def labels = labelManager.getLabels(issue.id).collect{it.getLabel()} labels -= 'labelToBeRemoved' labelManager.setLabels(user,issue.id,labels.toSet(),false,false)
The script is not tested by me, so be careful :-)
Henning
Is there any way to do this with the hosted version of Jira these days? We use a label of "merged" when branch code is merged into master and handed over to QA. but when QA re-opens the ticket, we wish to have that transition automatically remove said label if it exists (and of course, leave all the other labels !!!)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
script is also helpful after 3 years worked perfectly after changing line 4 to:
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For JIRA v7.x you need to change line 4 to:
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ville-Pekka,
that's exactly what's written in line 4. It's only another notation. In Groovy you could replace abc.getXyz() method calls with property access abc.xyz (remove get from the name, remove () and write the first letter in lower case). See http://groovy-lang.org/style-guide.html#_getters_and_setters
It could be written even shorter with
ComponentAccessor.jiraAuthenticationContext.loggedInUser
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oops. Way too long day behind last night
I did not even tested original code, but modified it first according to Alexander's comment.
Anyway this code is working and in our production now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
how can i do this with a custom-field from type label?
thx
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
It's nearly the same, there are getLabels() and setLabels() methods for customfields. E.g. see https://docs.atlassian.com/software/jira/docs/api/7.0.0/com/atlassian/jira/issue/label/LabelManager.html#setLabels-com.atlassian.jira.user.ApplicationUser-java.lang.Long-java.lang.Long-java.util.Set-boolean-boolean-
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I'm using JIRA v8.3.1 using the scriptrunner code above to clear the Label field. It's not clearing the field and I get no errors when it's run. Is there anything I need to do in my version of JIRA to get the Labels field to clear in Scriptrunner?
Thanks,
Randy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please disregard. Found a solution to my issue. I wanted to clear ALL labels so I used this code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels(issue.id).collect{it.getLabel()}
labels = ''
labelManager.setLabels(user,issue.id,labels.toSet(),false,false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the best way for you is to use Script Runner's post function
https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tags is Labels right?
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.