def str="1:one|2:two|3:three"
def i = "2"
def opts = str.split(/\|/)
def opt = opts.find { o -> o.contains("${i}:") }
echo "len: ${opts.length}"
echo "opt: ${opt}"
The output of which is
Started by user anonymous
Running: Print Message
len: 3
Running: Print Message
opt: false
Running: End of Workflow
Finished: SUCCESS
However, running effectively the same script in the Jenkins script console (or any other groovy environment I have tried) produces the expected result:
def str="1:one|2:two|3:three"
def i = "2"
def opts = str.split(/\|/)
def opt = opts.find { o -> o.contains("${i}:") }
println "len: ${opts.length}"
println "opt: ${opt}"
returns:
len: 3
opt: 2:two
Am I missing something really obvious or should I open a bug report for this?