Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Search Jira Assets from Scriptrunner using variables

Rob April 5, 2023

I am trying to use Scriptrunner to search my Assets for a particular object. However, the object will change so I would like to use a wild card/variable in my search. But I can't seem to figure out how to do that, if it is possible.

I can use Assets.search() in Scriptrunner and it works just fine if I am just typing in text much like I would do in a AQL/IQL search in Jira. But my objects I want to search for are currently in a groovy ArrayList and I want to step through each item and search for it. Just struggling on how to do it.

Was hoping for something kind of along the lines of this:

while (x <= myarraylist.size()) {

Assets.search("myObject = myarraylist[x]")

.....do something with it if it finds it kind of thing.......

x++}

 

Anyone have any thoughts?

1 answer

1 accepted

1 vote
Answer accepted
Rob April 11, 2023

Finally got something working for myself. Ended up figuring out I can use smart values in my scriptrunner script. It does give a cannot call error on the add line, but it does it, so just went with it. Code below incase it helps someone else.

Currently using this script as part of a Jira Automation item, so I'm not specifying a ticket in the code since the automation will pass me a ticket.

def myField = issue.getCustomFieldValue(12626)
def x = 0

String[] elements = myField.split(",")
List<String> fixedLengthList = Arrays.asList(elements)
ArrayList<String> listOfString = new ArrayList<String>(fixedLengthList)

while (x <= listOfString.size()) {
    if (Assets.search("CveID = ${listOfString[x]}")){
        issue.update {
            setCustomFieldValue('Tenable CVE Insight'){
                add("${listOfString[x]}")
            }
        }
    }
    x++
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events