How to write a groovy validation simple script runner checking components against a regular expression

Sheral Hewes December 18, 2014

Using JIRA 5.2.11

I want to validate that when a issue type "Library" is selected, only components that start with "Library" can be selected.

I have to components named "Library - model" and "Library - service"

My validation error displays no matter whether the component is something else or one of the Library ones above.

Please help.  Code below.

if (issue.issueTypeObject.name == "Library"){
    if(issue.components*.name ==~ /Library.*/){
        return true;
    } else {
        return false;
    }
} else {
    return true;
}

1 answer

1 accepted

0 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 18, 2014

You're doing a pattern match on a list, which won't work. You want something like (untested):

if (issue.issueTypeObject.name == "Library"){
    issue.componentObjects*.name.every { it ==~ /Library.*/ }
} else {
    true;
}
Sheral Hewes December 19, 2014

Worked Thanks!

Raj Kusumba August 13, 2020

Hi @JamieA 

I have similar requirement but the List names has a dot.

Like Library.model and Library.service

what is the pattern match of a dot ?

 

Thanks

Suggest an answer

Log in or Sign up to answer