Scriptrunner cloud - How to fast-track based on a specific label

Yuval Oren October 30, 2018

Hi,

I'm trying to fast-track issues based on a specific label. Ie, if label X if set then fast track (transition) the issue.

Here's the code I was using:

def issueLabels = issue.fields.labels
boolean containsLabel = false;


for (String label : issueLabels) {
if (label ==~ /(?i)test/){
containsLabel = true;
}
}

This code doen't fail but also doesn't work (Ie, issues with 'test' or 'Test' label are not transitioned).

 

Thanks,

Yuval

1 answer

1 accepted

0 votes
Answer accepted
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 3, 2018

Hi @Yuval Oren

Try getting labels using

 

import com.atlassian.jira.issue.label.LabelManager
...
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def issueLabels = labelManager.getLabels(issue.id)
Yuval Oren November 7, 2018

Thanks @Tom Lister. When I tried the following code I got these errors:

unable to resolve class com.atlassian.jira.component.ComponentAccessor

unable to resolve class com.atlassian.jira.issue.label.LabelManager

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.label.LabelManager;

LabelManager labelManager = ComponentAccessor.getComponent(LabelManager);
def issueLabels = labelManager.getLabels(issue.id);
boolean containsLabel = false;


for (String label : issueLabels) {
if (label ==~ /(?i)test/){
containsLabel = true;
}
}

 

Note: This runs on Jira cloud.

Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 8, 2018

Hi @Yuval Oren

I’m a server guy unfortunately 

looking at the migration guide here

http://scriptrunner-docs.connect.adaptavist.com/jiracloud/migrating.html#_logging

the cloud version use the REST API’s rather than plugin API

e.g.

def customFields = get("/rest/api/2/field")
.asObject(List) .body
.findAll { (it
as Map).custom } as List<Map>

def toUpdate1CfId = customFields.find { it.name == 'Custom Field 1' }?.id
def toUpdate2CfId = customFields.find { it.name == 'Custom Field 2' }?.id
def toUpdate3CfId = customFields.find { it.name == 'Custom Field 3' }?.id


thats as far as I can go with this
Yuval Oren November 8, 2018

@Tom Lister thanks for pointing me in the right direction :-)

I now have this code which works for me:

int total = post('/rest/api/2/search') 
.header('Content-Type', 'application/json')
.body(
[
jql: 'issuekey=' + issue.key + ' and labels in (test)',
fields: ["key"]
]).asObject(Map).body.total

total == 1

 

Basically using JQL result to evaluate the condition. I assume this could probably be achieved in a more efficient way but this solution works for Jira cloud. 

Like Tom Lister likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events