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.

10 thoughts on “Add labels when creating issue on JIRA

  1. Hey there! This is my first comment here so I just wanted to give a quick
    shout out and say I genuinely enjoy reading through your posts.
    Can you suggest any other blogs/websites/forums that cover the same topics?
    Many thanks!

  2. Good post. I learn something new and challenging on websites I stumbleupon everyday.
    It will always be exciting to read through content from other writers and use a little something from other web sites.

Leave a Reply

Your email address will not be published. Required fields are marked *