Hello all,
I would like to request a macro where on the labels are supposed to get updated automatically depending on the labels present on the Story task.I want the labels to be updated only if the Story has SEO_EMEA or MA_EMEA as one of its label.
Hello @sai_kiran
Do you have Script Runner plugin installed in your Jira instance ?
Yes it is
Here is a script you should add as a Listener of type Custom listener with events of type "Issue Updated":
// Listener to synchronise certains to label of certains// issues type to it's subtasksimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.label.LabelManagerdef labelMgr = ComponentAccessor.getComponent(LabelManager)def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser// List of label to synchronisedef labelsToCopy = ["SEO_EMEA", "MA_EMEA"]// List of issue type that we apply synchronisationdef issueType = ["Bug", "Story"]//Filter issue typeif (issueType.any{it == event?.issue.issueType.name}){ // Get changes of labels def labelsChange = event?.getChangeLog()?.getRelated("ChildChangeItem")?.findAll {it.field == "labels"} if (labelsChange) { //get issue def issue = event.issue // Get previous labels def previousLabels = Arrays.asList(((String)labelsChange.oldstring[0]).split()) // Get new labels def newLabels = Arrays.asList(((String)labelsChange.newstring[0]).split()) // Filter previous labels def previousLabelsToVerify = labelsToCopy.intersect(previousLabels) // Filter new labels def newLabelsToVerify = labelsToCopy.intersect(newLabels) // Compute labels to delete def labelsToDelete = previousLabelsToVerify - newLabelsToVerify // Compute labels to add def labelsToAdd = newLabelsToVerify - previousLabelsToVerify //get subtasks def subtasks = issue.subTaskObjects subtasks.each { subtask -> // get current label of the subtask def subtaskLabels = labelMgr.getLabels(subtask.id).collect{it.label} // Delete labels subtaskLabels -= labelsToDelete // Add labels subtaskLabels += labelsToAdd // Change labels of subtask labelMgr.setLabels(currentUser, subtask.id, subtaskLabels.toSet(), false, true) } }}
Just configure the two first array:
If you need all issueType this can be easyly modified (delete first if)
If you need a filter on subtasks issueType create a filter on the subtasks collection.
Regards,
Adrien
Thank you, perfect solution!
It looks like you're new here. Sign in or register to get started.