You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!


Update the Labels for an Issue in Jira


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.


  • Jira Jira (8.0 - 8.14)
  • ScriptRunner for Jira ScriptRunner for Jira (6.18.0)
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.label.LabelManager // 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(*.label def labelsToSet = (existingLabels + newLabels).toSet() labelManager.setLabels(loggedInUser,, labelsToSet, sendNotification, causesChangeNotification)
Discovered an issue? Report it here

Suggested for you