Jenkins管道java.io.NotSerializableException:groovy.util.slurpersupport.NodeChildren

时间:2017-04-24 04:27:11

标签: jenkins groovy jenkins-pipeline

我正在尝试从Jenkinsfile运行管道作业(使用Groovy代码)但是我收到以下错误 -

java.io.NotSerializableException: groovy.util.slurpersupport.NodeChildren
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:778)
    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.doWriteSerializableObject(RiverMarshaller.java:967)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    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)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
    at java.util.HashMap.internalWriteEntries(HashMap.java:1777)
    at java.util.HashMap.writeObject(HashMap.java:1354)
    at sun.reflect.GeneratedMethodAccessor101.invoke(Unknown Source)
...

我想要执行的代码是 -

def getDataVersionFromNexus() {
    def user = params.nexusUser
    def password = params.nexusPassword    
    ...

    def oldVersion = -1
    print output
    if (!output.isEmpty()) {        
        def xmlContent = new XmlSlurper().parseText(output)
        oldVersion = "${xmlContent.versioning.release}"
    }

    return oldVersion
}

我试图将方法注释为@NonCPS(如类似的SO帖子所示)但是我没有得到正确的输出。

1 个答案:

答案 0 :(得分:1)

尝试将此值作为列表复制到ArrayList,然后使用。 例如,像这样:

tmp = xmlContent.versioning.release.toList()
list = new ArrayList()
for (i = 0; i != tmp.size(); i += 1) {
    list.add(tmp.get(i))
}
oldVersion = list.get(0)