How to fix NotSerializableException error during Jenkins workflow build?

≡放荡痞女 提交于 2019-11-29 03:23:51

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-of-local-variables

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...

According to CloudBees Platform Help page:

By design the pipeline can only keep records of Serializable objects. If you still need to keep an intermediate variable with a non serializable object, you need to hide it into a method and annotate this method with @NonCPS.

So you should transform your code into a function with @NonCPS helper method.

Related Jenkins bug: JENKINS-27421.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!