Unable to retrieve a match string

HI, I have the following snippet of code via Groovy ScriptRunner.

Issue currIssue = componentManager.getIssueManager().getIssueObject("TESTDEV-712")

def targetVersion = currIssue.getCustomFieldValue(cf)
log.debug targetVersion

def fixVersion = currIssue.getFixVersions()
log.debug fixVersion

fixInHead = fixVersion.grep('HEAD')

log.debug fixInHead

if (fixVersion.contains(targetVersion))
   log.debug "Found match"
   log.debug "No match"


My test data is:

Target Version = 8102

Fix Version = 8102, HEAD

Expected it to return "Found match" but for some unknown reason, it doesn't see the match. Please help! Thanks!

3 answers

1 accepted

1 vote
Accepted answer

target version and fix version are both lists.

I would suggest you to change "contains" to "containsAll"

if (fixVersion.containsAll(targetVersion))
   log.debug "Found match"
   log.debug "No match"

This will work if the target version would be one or multiple selections

Thanks! That works. I have a follow-up question. What's the call that I can make to return the list count? I'm new with groovy scripting.

To retrieve the list count you can use the size() method. So "fixVersion.size()". The answer depends by the purpose of your script. If you are creating a scripted field just take a look at that: https://jamieechlin.atlassian.net/wiki/display/GRV/Scripted+Fields

Thanks - got the script to work. Much appreciated.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,686 views 3 11
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