It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Check if issue contains specific label with Groovy Script

Vladimir Pekin Feb 11, 2015


I'm trying to write a post-function which will change issue description if some conditions are met during issue creating.

I'm stuck on the following stage: I need to check whether specific label is in issue's labels. In particular i want to check if issue contains label "Internal Project" despite it can contain a lot of other labels (e.g. labels for the issue are "Critical", "Internal project", "High LoE").

Could you advise me how I can check it?

Also please advice where I can download JIRA libs for work in Intellij IDEA if you know. This is much easier to work with project on PC.

My code is:


import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
//get IssueManager for getting of issues
IssueManager issueManager = ComponentManager.getInstance().getIssueManager()
//get customFieldManager
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
//retrieve current issue (works for workflow post-functions)
//MutableIssue issue = issue
//Check whether the issue contains "Internal Project label"
//retrieve an issue which we want to use for getting additional description
MutableIssue issueForDescription = issueManager.getIssueObject("FOO-5")
//amend the issue description if issue is not subTask
if (!issue.isSubTask()) {
if (issue.description == null) {
issue.description = issueForDescription.description
} else {
issue.description = issue.description + issueForDescription.description
//If the issue already created and you change the issue object after that, you have to update the issue manually. Do it with following code. This is not needed in post-functions!
user = componentManager.jiraAuthenticationContext.getLoggedInUser()
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
//result parameter is used for debugging in Script console
result = "Issue description is updated."
} else {
result = "Issue is subtask. Issue isn't updated."
} else {
result = "Create multiply issues field doesn't exist for this issue or is not filled. Nothing was updated."

3 answers

1 accepted

4 votes
Answer accepted

I would suggest you to install the Atlassian SDK ( )

Then checkout and import this project using IDEA:

After doing that, IDEA should know where Maven from SDK is installed.

You can retrieve this info with the command from the shell:




In the output you can see this line:


ATLAS Maven Home: /usr/share/atlassian-plugin-sdk-5.0.3/apache-maven-3.2.1


Override the IDEA Maven configuration with that new location.

Screen Shot 2015-02-12 at 10.29.30.png


After that go to your project root (where the pom.xml is) and start the command "atlas-debug" from terminal.

When JIRA is started you can run a remote debug with IDEA to localhost port 8005

You may also want to specify a folder in which you have your scripts:

atlas-debug --jvmargs -Dplugin.script.roots=ABSOLUTE_PATH/scripts

This prevents uploading your code every time you change it.

Vladimir Pekin Feb 12, 2015

Thanks you very much for this detailed manual! I've made steps by "After that go to your project root (where the pom.xml is) and start the command "atlas-debug" from terminal." and got working project. When I typed atlas-debug I've got: me@MYPC /e/Repository/sr-scripts-plugin (master) $ atlas-debug sh.exe": atlas-debug: command not found This is not critical for me.

Probably your SDK commands are not on path. sh.exe? I never did it on windows, try to take a look at that:

Vladimir Pekin Feb 12, 2015

I was performing this from Git Bash, from cmd.exe it works. Thank you for your help!

1 vote
Vladimir Pekin Feb 12, 2015

Finally I was able to read and check labels with following code:

Set issueLabels = issue.getLabels();
boolean containsLabel = false;

for (String label : issueLabels) {
    if (label.contains("Client_implementation-")){
        containsLabel = true;

To get methods I was using

1 vote

That is equivalent to:

def containsLabel = "Client_implementation-" in issue.getLabels()*.label

I would suggest you to take a look at that:

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Webinar alert! An IT Admin's Guide to Securing Collaboration at Scale

Hello, Atlassian Community! My name is Dave Meyer and I'm a Principal Product Manager at Atlassian. I wanted to give this community a heads up about an upcoming Webinar that might be of interest...

172 views 2 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you