Greetings,
I am wondering whether it is possible to add a label to a Jira ticket while progressing through a work flow.
It seems like that would be something a post-function can do, but it seems I am unable to.
Thanks.
Here's some example code for script runner that does that:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.bc.issue.label.LabelService import com.atlassian.jira.bc.issue.label.LabelService.AddLabelValidationResult import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.security.JiraAuthenticationContext import com.opensymphony.user.User import org.apache.log4j.Category ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() JiraAuthenticationContext authenticationContext = componentManager.getJiraAuthenticationContext() User user = authenticationContext.getUser() LabelService labelService = ComponentManager.getComponentInstanceOfType(LabelService.class) MutableIssue myIssue = issue ["somelabel", "someotherlabel"].each {String labelName -> AddLabelValidationResult validationResult = labelService.validateAddLabel(user, myIssue.id, labelName) if (!validationResult.errorCollection.hasAnyErrors()) { labelService.addLabel(user, validationResult, false) } }
For JIRA 7 you would use:
import com.atlassian.jira.bc.issue.label.LabelService import com.atlassian.jira.bc.issue.label.LabelService.AddLabelValidationResult import com.atlassian.jira.component.ComponentAccessor def authenticationContext = ComponentAccessor.getJiraAuthenticationContext() def user = authenticationContext.getLoggedInUser() def labelService = ComponentAccessor.getComponent(LabelService) ["somelabel", "someotherlabel"].each {String labelName -> AddLabelValidationResult validationResult = labelService.validateAddLabel(user, issue.id, labelName) if (!validationResult.errorCollection.hasAnyErrors()) { labelService.addLabel(user, validationResult, false) } }
It would be possible with the Script Runner plugin.
Here it is some documentation. But basically you can create a Script PostFunction that could add a label in the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried this solution on both JIRA server and cloud. No need for script runner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this 'Post functions' solution.
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.
can you see if there is anything in the logs...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.opensymphony.user.User
@ line 7, column 1.
Script18.groovy: 7: unable to resolve class com.opensymphony.user.User
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
The User class in your code seems not present in the latest JIRA (I'm using 6.3.10)
That's why this code is worng now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've updated my answer for JIRA 7. It will probably work on JIRA 6.3... the main thing is to remove the old User import.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, you can find useful code here: https://answers.atlassian.com/questions/172565/any-way-to-remove-a-label-on-resolution
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.