jenkins – 这个共享库中的“不可序列化”是什么,我该如何解决?

使用Jenkins管道插件时,构建失败并出现 java.io.NotSerializableException错误,如下所示:

java.io.NotSerializableException: org.codehaus.groovy.control.ErrorCollector
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    ...
Caused by: an exception which occurred:
    in field collector
    in field abnormal
    in field outcome
    in field body
    in field step
    in field thread
    in field this$0
    in field returnAddress
    in field parent
    in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@6ae7e4f1
    ...
Finished: FAILURE

当我使用带有一些import语句的自定义库时会发生这种情况.我已经尝试了几件事,比如用@NonCPS封装调用方法,但错误仍然存​​在.

管道脚本

#!groovy
@Library('utils')

pipeline {
    agent any
    stages {
        stage('Run Script') {
            script {
                myScript param1
            }
        }
    }
}

瓦尔/ myScript.groovy

import com.company.jenkins.utils

def call(String param = "test") {
    def libScript = LibScript(this)
    libScript.printMessage("Hello World")
}

SRC/C++OM /公司/jenkins/ utils的/ LibScript

package com.company.jenkins.utils;

// This import works fine
import groovy.json.*

// This one fails
import groovyx.net.http.RESTClient

class LibScript implements Serializable {
    def steps
    def client

    LibScript(steps) { this.steps = steps }

    def printMessage(String message) { steps.echo "Saying: " message }

    // This also fails
    @NonCPS
    def doSomething() { client = new groovyx.net.http.RESTClient( 'https://somehost/' ) }
}

使用的版本:

>jenkins:2.19.3
>管道插件:2.5
>管道共享Groovy库插件:2.7

由于编译错误,将出现此错误.这不是一个很好的堆栈跟踪.但是你有一个非序列化对象作为你的变量之一或者在字符串的中间(可以将变量值作为’..“$var”..’).为此,我附上了两个链接.请仔细阅读,你会明白出了什么问题.请一步一步地了解哪里出了问题.

1)https://issues.jenkins-ci.org/browse/JENKINS-40109

2)https://coderwall.com/p/zvsh5q/jenkins-load-command-can-t-found-why-i-have-a-java-io-notserializableexception

相关文章
相关标签/搜索