//Add labels in bulk witth issue key
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.label.Label
import com.atlassian.jira.issue.label.LabelManager
// Define the issue keys you want to search for
def issueKeys = [key-xxxx, key-xxx2]
IssueManager issueManager = ComponentAccessor.getIssueManager()
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager.class)
issueKeys.each { key ->
Issue issue = issueManager.getIssueByCurrentKey(key)
if (issue) {
Set<Label> existingLabels = issue.getLabels()
boolean hasDevLabel = existingLabels.find { it.getLabel().equalsIgnoreCase("DEV") }
// Add 'DEV' label if it doesn't already exist
if (!hasDevLabel) {
labelManager.addLabel(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue.getId(), "DEV", false)
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter