Categories
Tools

Add labels when creating issue on JIRA

JIRA is definitely a flexible bug tracking tool and one of the most powerful features is workflow customization. This post describes how to add a label automatically when an issue is created. This can be useful when you want to flag an issue and later capture that in a filter or board. A practical example is to flag Bugs that are created so that they can be reviewed during Bug Scrub meetings. In order to add a label we need to add a custom script in a post-function.

  1. As admin, go to Administration >> Issues >> Workflows >> Click on Edit in the workflow you want to change
  2. Click on the ‘To Do’ step (assuming your workflow is the default one)
  3. Click on the ‘Create’ action >> Post Functions tab >> Add post function
  4. Select Script Post-Function >> Custom script post-function
  5. Paste the following code snippet replacing ‘BugScrub’ by the tag you want
  6. Publish the workflow => Important: If you don’t publish the draft workflow, no changes will be reflected.
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.component.ComponentAccessor

def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

LabelManager mgr = ComponentAccessor.getComponent(LabelManager.class)
mgr.addLabel(user, issue.id, 'BugScrub', false)

 

For additional information about the addLabel method, please refer to the official documentation.