Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I create an email notification every time an issue is labeled or unlabeled?

I would like to create an email notification that is triggered every time an issue is labeled or unlabeled with a specific label. I've attempted to and don't believe this can be achieved with out of the box notifications with Jira. I also don't want to use a post function because I don't want the trigger dependent on a transition. Will I need to write some custom groovy? Is there an out of the box listener that exists for this already? Thanks in advance.

1 answer

1 vote
Ravi Sagar Community Leader Oct 15, 2019

Hi @Matt Marino 

What you can do is use the following code in Send a custom email listener's Condition and Configuration section.

Label added

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def previousLabels = changeHistoryManager.getChangeItemsForField(issue, "labels") ? changeHistoryManager.getChangeItemsForField(issue, "labels").last().getFromString(): ""
def newLabels = changeHistoryManager.getChangeItemsForField(issue, "labels") ? changeHistoryManager.getChangeItemsForField(issue, "labels").last().getToString():""
if (previousLabels == "" && newLabels == "") {
//No existing labels
return false
}
else if (newLabels.indexOf("LABEL") == -1) {
//Label removed
return false
}
else if (previousLabels.indexOf("LABEL") == -1 && newLabels.indexOf("LABEL") > -1) {
//Label added
return true
}

Label removed

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def previousLabels = changeHistoryManager.getChangeItemsForField(issue, "labels") ? changeHistoryManager.getChangeItemsForField(issue, "labels").last().getFromString(): ""
def newLabels = changeHistoryManager.getChangeItemsForField(issue, "labels") ? changeHistoryManager.getChangeItemsForField(issue, "labels").last().getToString():""
if (previousLabels == "" && newLabels == "") {
//No existing labels
return false
}
else if (newLabels.indexOf("LABEL") == -1) {
//Label removed
return true
}
else if (previousLabels.indexOf("LABEL") == -1 && newLabels.indexOf("LABEL") > -1) {
//Label added
return false
}

You can create two listeners - one for label added and the other one for label removed.

Let me know if this works.

Ravi

That worked! The email isn't firing every time, but that is a separate problem for me to resolve. Thank you for your help!

Like Ravi Sagar likes this

@Ravi Sagar Let me know if this is the wrong forum for this followup. I've got the custom emails set up with above code above (adjusted for my custom label) in the Condition and Configuration, and have tried using All Issue Events, Generic Events, and Issue Updated as which events to fire on. Instead of sending an email only when the label is added or removed, it's seemingly firing on almost every update to issues. Any insight?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

551 views 15 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you