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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,644
Community Members
 
Community Events
185
Community Groups

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 _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
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 _Sparxsys_ likes this

@Ravi Sagar _Sparxsys_ 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
AUG Leaders

Atlassian Community Events