Im working in a pipeline with groovy and I found this problem with find operator where all solutions didn't work.
after this code:
stage('Get build artifacts') {
def buildNumber = (params.BUILD_VERSION =~ /^.*-b(\d*)-(.*$)/)
I do a wget to download artifacts, but appears this error
an exception which occurred:
in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@325d4820
in field com.cloudbees.groovy.cps.impl.CpsClosureDef.capture
in object com.cloudbees.groovy.cps.impl.CpsClosureDef@31fe6d7d
in field com.cloudbees.groovy.cps.impl.CpsClosure.def
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@68074406
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@4842ad69
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@4842ad69
Also: org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: a9fb8438ab8f-4ab2-9ee7-83b8f48ed2d3
Caused: java.io.NotSerializableException: java.util.regex.Matcher
I need to use a second part to a build url with that parts, so I will have 3 values in this var.
code example will be:
wget https://mywebsite/''' + buildNumber[0][2] + '''/'''+ buildNumber[0][1] + '''/pkg1-''' + params.BUILD_VERSION + '''.tar.gz
wget https://mywebsite/''' + buildNumber[0][2] + '''/'''+ buildNumber[0][1] + '''/pkg2-''' + params.BUILD_VERSION + '''.tar.gz
My build number needs to be like 1.0.0-b1-master but fails when downlaods second package and I can't find a solution. Most curios is because this code is working in one jenkins and creating second now fails. Idees?
Thanks!
PD: Edited with more context after first answer received
Basically what the error says -
Matcheris not serializable. Why is it a problem? Here is the short answer from Jenkins documentation:If you want to know more you can google what CPS is, but that rabbit hole is pretty deep. In your case this is probably the quickest fix:
Update
If you need all matches and groups you can convert
Matcherto aList: