简体   繁体   中英

Not serializable error for jenkins declarative pipeline

I am trying to trigger my email promotion job from my pipeline which extracts the repo name from Jenkins messages. But not able to resolve the SerializableException error for this block. Any help is greatly appreciated.

post{
        success{
            script{
                @NonCPS
                //upstream_job_name = null
                def manager = manager.getLogMatcher('.*Obtained Jenkinsfile from git (.*)$')
                if(manager.matches()){
                    def gitMsg=manager.group(1)
                    gitrepo = "${gitMsg}"
                    echo gitrepo
                    def upstream_job_name = gitrepo.split("/")[4].replace(".git", "")
                    println upstream_job_name

                }
                build job: 'job-approval' , parameters: [[$class: 'StringParameterValue', name: 'upstream_job_name', value: upstream_job_name]]


            }
        }
    }

Below is the error messages i am receiving :

[Pipeline] // script Error when executing success post condition:

java.io.NotSerializableException: java.util.regex.Matcher at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:926) at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65) at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56) at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50) at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)

You need to release manager immediately after using. More detail can find in this post

script{

    //upstream_job_name = null
    def manager = manager.getLogMatcher('.*Obtained Jenkinsfile from git (.*)$')
    if(manager.matches()){
        def gitMsg=manager.group(1)
        gitrepo = "${gitMsg}"
        echo gitrepo
        def upstream_job_name = gitrepo.split("/")[4].replace(".git", "")
        println upstream_job_name      
    }
    manager = null

    build job: 'job-approval' , 
        parameters: [
            [$class: 'StringParameterValue', name: 'upstream_job_name', value: upstream_job_name]
        ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM