How to fix NotSerializableException error during Jenkins workflow build?
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:
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.