I\'m working on a jenkinsfile and I\'m getting and exception in the third stage:
an exception which occurred:
in field com.cloudbees.groovy.cps.impl.BlockSco
Your problem is this line:
def has_snapshot = artifact_name =~ /-TEST\.jar/
The =~
is the Groovy find operator. It returns a java.util.regex.Matcher instance, which is not Serializable. If Jenkins decides to pause your script after you have stored the result in a local variable that is serialized by Jenkins that is when you get the exception. This can be easily tested by immediately adding a sleep(1)
step after your invocation and watch as that same exception is thrown.
To resolve this, you should :
java.util.regex.Matcher
result in CPS transformed code@NonCPS
annotated method or use the match operator (==~) which returns a boolean (if it fits your use case)