I'm having trouble parsing the jenkins pipeline console output. Every time I pass a job, a line appears in the console:
12:29:08 [10:29:07] NIDD version is: SBTS23R1_NIDD_2217_100_01
I would like to extract a variable value from it: SBTS23R1_NIDD_2217_100_01 and save it in a variable so that I can use it further.
I tried to do something like described here: GROOVY: Finding a string from console output if a regexp string found
Unfortunately, I am getting the error:
an exception which occurred:
in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@20cd216a
in field com.cloudbees.groovy.cps.impl.CpsClosureDef.capture
in object com.cloudbees.groovy.cps.impl.CpsClosureDef@3e3cd6ed
in field com.cloudbees.groovy.cps.impl.CpsClosure.def
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@6be3d3c7
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@14fde9cd
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@14fde9cd
Caused: java.io.NotSerializableException: java.util.regex.Matcher
My code :
def matcher = ("12:29:08 [10:29:07] NIDD version is: SBTS23R1_NIDD_2217_100_01" =~ /NIDD version is:\SBTS\d{2}\w\d_NIDD_\d{4}_\d{3}_\d{2}/)
if (matcher.hasGroup())
{
def msg = matcher[0][1] println("Build failed because of ${msg}")
}