Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Add labels using script runner Cloud

K Vivek Rao May 4, 2025 edited

Hi I am learning script runner.

As a beginner my use case is, In jira cloud when issue moves to inprogress state i want to add label to the issue as "Test"

Guide me with steps to achieve the same.

 

3 answers

1 accepted

0 votes
Answer accepted
K Vivek Rao May 7, 2025

Here is the code that will work for script runner cloud

Issues.getByKey(issue.key as String).update{
setLabels{
add("TestLabel")
}
}

 

2 votes
Piyush Annadate _ACE Pune_
Community Champion
May 4, 2025

Hello @K Vivek Rao ,
Since you said, CLOUD + Scriptrunner, here's the snippet for it:

List labels = issue.fields.labels ?: [] // get the labels for the current issue
labels += "newLabel"
issueInput.fields.labels = labels

 

Alternatively, you can use JIRA Automation to perform the actions.

Tip: While adding a labels, add to existing labels, else one may replace all with new.  

K Vivek Rao May 4, 2025

Screenshot 2025-05-04 at 3.09.57 PM.png

 

Thank you @Piyush Annadate _ACE Pune_  for your input, but i am getting the error as attached. I am configuring it as a part of post-function on In Progress transition.

 

If issue is moved to In progress state, a label "test" should be added under lables, it should append not replacing.

 

 

Piyush Annadate _ACE Pune_
Community Champion
May 4, 2025

Hi,
With post function, you can just added as below:

issueInput.update.labels = [[set: ["example"]]] // to set just the value.

Else

List<String> labels = Issues.getByKey(issue.key).getLabels()?.collect { it.label } ?: [] // get the labels for the current issue

labels += "updateLabel"

issueInput.fields.labels = labels

With error, save and test. 
0 votes
yqiao
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 4, 2025

If you prefer a no-code solution, Jira Automation can achieve the same result. Follow these steps:

Step-by-Step Instructions

  1. Create a New Automation Rule:

    • Go to the project settings and navigate to Automation.

    • Click on "Create Rule."

  2. Set the Trigger:

    • Select the "Issue Transitioned" trigger.

    • Configure the trigger to fire when the issue transitions to the "In Progress" state.

  3. Add a Condition (Optional):

    • If needed, add a condition to ensure the rule only applies to specific issues or projects.

  4. Add an Action:

    • Select the "Edit Issue" action.

    • In the "Fields to Set" section, choose "Labels."

    • Add the label "Test" to the field. If other labels exist, ensure they are preserved by appending "Test" rather than overwriting the field.

  5. Save and Enable the Rule:

    • Review the rule configuration.

    • Save and enable the rule.

  6. Test the Automation:

    • Transition an issue to the "In Progress" state and verify that the "Test" label is added automatically.

K Vivek Rao May 7, 2025

I know this jira automation, i was specifically asking for Script runner

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events