Within Jira issues or a project in Jira, you may require labels to help with categorising or searching for issues.
For example, you may want to aplly the label 'Accounting' to all issues related to accounting and financing. Use this script to automate adding labels to issues.
I want to add labels to issues based on keywords appearing in posted comments. I can use this script to do this, so I don't have to manually add labels.
// the issue key of the issue to update its labels
final String issueKey = "JRA-1"
// change to 'false' if you don't want to send a notification for that change
final boolean sendNotification = true
// have this true in order to throw an issue update event, and reindex the index
final boolean causesChangeNotification = true
// a list with the labels we want to add to the issue
final List newLabels = ["label_a", "label_b"]
def issueManager = ComponentAccessor.issueManager
def labelManager = ComponentAccessor.getComponent(LabelManager)
def issue = issueManager.getIssueByCurrentKey(issueKey)
assert issue : "Could not find issue with key $issueKey"
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def existingLabels = labelManager.getLabels(issue.id)*.label
def labelsToSet = (existingLabels + newLabels).toSet()
labelManager.setLabels(loggedInUser, issue.id, labelsToSet, sendNotification, causesChangeNotification)