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.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.