NotSerializableException in jenkinsfile

前端 未结 1 1696
感情败类
感情败类 2021-01-02 20:21

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         


        
相关标签:
1条回答
  • 2021-01-02 20:36

    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 :

    • Not store the java.util.regex.Matcher result in CPS transformed code
    • Move the usage into a @NonCPS annotated method or use the match operator (==~) which returns a boolean (if it fits your use case)
    0 讨论(0)
提交回复
热议问题