Is there a way to automatically add a Label for a created JIRA issue?

Johnson Wang May 21, 2015

I've setup a Zapier integration so that any new alerts in PagerDuty will create a new issue in JIRA for our Ops team to see.

Is there any way to automatically add a Label to these newly created JIRA issues? So the workflow might look like:

PagerDuty alert > new JIRA issue created > the "PD-Alert" Label is automatically added to the JIRA issue

Is this possible at all?

8 answers

12 votes
Ole Kristian Brattli September 5, 2017

Solved this without expensive plugins for Jira enterprise V7.4.2:

1 Edit the workflow->"create transition" to add a post function to the create step. 

2 (for some reason you cant edit label as a field directly) so add your label-name to a tmp custom field that is a text string.

3 add another post function that copied this field to the labels field

4 clear the tmp custom field value.

Spyder McHenry August 3, 2018

This is an excellent answer! Though, can you think of a way to filter this on an issue created by email? Meaning, if you only want to auto-label issues created by email... 

Like # people like this
Sai sampath Bharadwaj garikipati April 24, 2020

Can you please let us know the steps creating label-name to tmp custom field in Jira workflow post functions.

AlexV May 21, 2020

He just did. I read the post, and created exactly what Ole outlined in less than 5 minutes.

Now, having to do these steps without an ability to directly append a label is undelightful.

Kamran786 July 29, 2020

@Ole K_ Brattli 

What if I have more than two fields that I need to add it in a label. 

In that case that post function I.e copying a field to label might not work. 

Can you kindly help me in suggestions alternative for this. This will solve a major problem of mine. 

I have 3-5 fields which I need to add as a label. After a customer creates a ticket. 

AlexV August 5, 2020

use Zapier (or azure function or some other ITTTF tool). It has a lot of runway for free and it's soooooooooooo much easier to deal with that inadequacies of Jira UI.

3 votes
TZR June 28, 2018

Use Jira Automation plugin, the Lite (free) version should work.

  1. Trigger: Issue Created
  2. Condition: Your JQL condition
  3. Action: Issue Edit
    • Select the Labels field and add in the required label(s)

Pros:

  • working for Jira v7.10
  • easy configuration/maintenance
  • no scripting involved

Cons:

  • update is done after an event trigger
    • this means you have to refresh the page for the update to reflect on the issue if the Trigger is a workflow transition event
  • actor is a fixed user (i.e. the user that update the change is always the same Jira user for each automation, it cannot be the logged in user or reporter etc.)
Ian Ang June 28, 2018

Thanks! This works :)

Jim Cork December 19, 2018

Good solution that doesn't require hacks.

Maitrey Patel
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 12, 2019

This addon allows only 3 rules per project.

TZR February 12, 2019
This addon allows only 3 rules per project.

Didn't know that, or is it only for Lite version?

I tried on eval and managed to add 4 rules to the same project. Maybe a workaround is to set projects as Global and then specify the project restriction in the Rule's Condition

megan.milan March 4, 2019

What JQL did you use? I tried "Linked_Intercom_Conversation IS Not "Blank"" and got an error message. 

mario June 4, 2019

As an added option, you could add a second automation to remove the label upon Status change or another trigger. For instance, if the label was used to identify new issues easily, the label could be automatically removed when assigned or when the status changes.

Like Jens Wölke likes this
3 votes
abhijit roy September 26, 2017

*This is a fix for Jira Service Desk*

I was able to solve this with a simple non workflow related workaround

Project Settings -> Request types- >Edit the request you want to add labels to -> Add  a "Hidden" labels field with the label you need in "Preset value". This will ensure that when the issue is created, the label automatically gets added to a issue of that type.

Kamran786 June 24, 2020

After request types i did not get what exactly is edit request as currently i have two options one is edit field and edit group. Can you kindly help m here

0 votes
ArowinLifeDirect March 25, 2019

I just set this up on our site with "Project automation" (which I think is now just built into Jira?)

For us I wanted a way to add "to-groom" to all new cases. I ended up with

 

When: Issue created
If: Issue matches JQL "(labels is EMPTY OR (labels != "to-groom" AND labels != "groomed")) AND status != Resolved AND status != Closed"
Then: Edit issue fields: Labels SET "to-groom"

0 votes
Joffrey_Hamman March 8, 2019

With Scriptrunner, you can add this custom script post-function on the transition Create:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

def user = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()

def labelManager = ComponentAccessor.getComponent(LabelManager)
labelManager.addLabel(user,issue.id, "Your label here", false)

0 votes
somashekhar November 28, 2015

@Rodrigo Sogari [Atlassian] HI

How to add 'Labels' automatically on Transition/State change ( i.e  changing the bug status (Ex) to 'Open' to 'close' state.Does JIRA support for this.

Please Comment.
Thanks 

Jim Cork December 19, 2018

Jira Automation lite plugin should be able to solve this.

0 votes
Johnson Wang May 21, 2015

@Rodrigo Sogari [Atlassian] Thanks for the very quick reply – much appreciated.

Script Runner looks promising but it does not run on Cloud instances. Bummer. Do you have any other suggestions?

Chris Cooke March 22, 2018

ScriptRunner is available on Cloud these days!
Marketplace Link Here

0 votes
Rodrigo Rosa
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 21, 2015

Hi Johnson,

JIRA does not have a built-in feature for that, but I believe you should be able to achieve this with a custom script using the Script Runner plugin.

I've found a script to add labels automatically. Maybe you can customize that script.

https://answers.atlassian.com/questions/56290/auto-assign-labels-based-on-the-user-group

Hope this helps

AlexV June 24, 2020

So - 5 years later. Lets bump this.

The question is "why not?". We shouldn't need script runner or direct sql quries which are not even available in the cloud version.

As it stands now, the workflow is to set a label on another field, then copy it to the field i want. It's not very delightful, and it wipes out all of the labels in the process.

Like # people like this
Ole K_ Brattli July 29, 2020

Supporting AlexV in this!

About to embark on the cloud-version of this adventure after migrating our stuff to cloud and having to recreate this. Fully expecting it to be at least as "undelightful" still

David Thomas August 13, 2020

no delights I wish for a better solution too 

Suggest an answer

Log in or Sign up to answer