Jenkins groovy regex match string : Error: java.io.NotSerializableException: java.util.regex.Matcher Jenkins groovy regex match string : Error: java.io.NotSerializableException: java.util.regex.Matcher jenkins jenkins

Jenkins groovy regex match string : Error: java.io.NotSerializableException: java.util.regex.Matcher


This problem is caused by Jenkins' CPS, which serializes all pipeline executions to store as resumable state.

Calls to non-serializable methods have to be wrapped in a method annotated with @NonCPS:

@NonCPSString getVersion(String binaryName) {  def matches = (binaryName =~ /(V)(\d+)(_)(\d+)(_)(Build)(_)(\d+)/)  versionTag = ""+matches[0].getAt(0)  versionTag}

this method can now be called from your pipeline. In case your Jenkins master restarts during execution of this method, it would just run through it completely - which is in many cases, such as yours, absolutely no problem.