问题描述
当我在Jenkins工作流程(Jenkins 1.609.1,工作流程1.8)上运行以下代码时,出现"NotSerializableException"错误(同样在下面).但是,如果我将构建作业"移到用于"范围之外,则可以正常工作(该作业已激活).任何想法为什么这种行为?
When I run the following code on the Jenkins workflow (Jenkins 1.609.1 ,workflow 1.8) I get error of 'NotSerializableException' (also below).However, if I move the "build job" outside the "for" scope it works fine (the job is activated). Any ideas why this behavior?
node('master') {
ws('/opt/test) {
def file = "/ot.property"
def line = readFile (file)
def resultList = line.tokenize()
for(item in resultList )
{
build job: 'testjob_1'
}
}
}
错误:
Running: End of Workflow
java.io.NotSerializableException: java.util.ArrayList$Itr
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)
.....
推荐答案
我想这是因为它试图在到达build job
步骤后立即序列化resultList
上不可序列化的item
迭代器.有关使用不可序列化变量的指南,请参见此处:
I thnk it is because it's trying to serialize the unserializable item
iterator on resultList
as soon as it hits the build job
step. See here for guidance on use of nonserializable variables:
https://github.com/jenkinsci/workflow -plugin/blob/master/TUTORIAL.md#serialization-local-variables
作为使用工作流插件进行安全迭代的一种解决方法,您需要使用C风格的循环.尝试以下方法:
As a workaround to safely iterate using the workflow plugin, you need to us C-style loops. Try this instead:
for ( int i = 0; i < resultList.size; i++ ) {
etc...
这篇关于如何在Jenkins工作流程构建期间修复NotSerializableException错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!