Jira Jelly how do I add label to an issue?

Hi

I am needing to set a label on an issue in my jelly script, I know how to get the labels, but I cant find anything in the javadocs that allows me to create a new label or get an existing label to set on an issue:

<core:invoke on="${issueKey}" method="getLabels" var="labels" />

<!-- Get or create a label -->

<core:invoke on="${labels}" method="add" var="flag">

<core:arg type="com.atlassian.jira.issue.label.Label" value="???" />

</core:invoke>

<core:invoke on="${issueKey}" method="setLabels">

<core:arg type="java.util.Collection" value="${labels}" />

</core:invoke>

Any help would be very much appreciated, thank you!

1 answer

1 accepted

You can use the LabelManager, like this:

&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
&lt;JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.JiraTagLib" xmlns:core="jelly:core" xmlns:log="jelly:log"&gt;

    &lt;jira:CreateProject key="XYZ" name="XYZ Project" lead="admin"&gt;
        &lt;jira:CreateIssue summary="Rocket thrusters not firing" reporter="admin" assignee="admin" issueIdVar="issueId" /&gt;
    &lt;/jira:CreateProject&gt;

    &lt;core:invokeStatic className="java.lang.Class" method="forName" var="clazz"&gt;
        &lt;core:arg type="java.lang.String" value="com.atlassian.jira.issue.label.LabelManager" /&gt;
    &lt;/core:invokeStatic&gt;

    &lt;core:invokeStatic className="com.atlassian.jira.component.ComponentAccessor" 
                       method="getComponent" var="labelManager"&gt;
      &lt;core:arg type="java.lang.Class" value="${clazz}" /&gt;
    &lt;/core:invokeStatic&gt;

    &lt;core:invoke on="${labelManager}" method="addLabel"&gt;
     &lt;core:arg type="com.atlassian.crowd.embedded.api.User" value="${jelly.user}" /&gt;
     &lt;core:arg type="java.lang.Long" value="${issueId}" /&gt;
     &lt;core:arg type="java.lang.String" value="oops" /&gt;
     &lt;core:arg type="boolean" value="false" /&gt;
    &lt;/core:invoke&gt;
&lt;/JiraJelly&gt;

Awesome, once again you are a master, thanks David.

Is this possible without updating the updatedDate, too? e.g. the comment manager has a flag "tweakIssueUpdateDate".

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

247 views 4 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you