Jenkins pipelines must be built so they can run across multiple executors, even if you only run Jenkins with one executor

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

A bit hidden, and important for anyone using Jenkins, This fact should be better known:

Serialization and the “node” Block
Jenkins pipelines must be built so they can run across multiple executors, even if you only run Jenkins with one executor. This is done using the node block. With it, a job can be split into smaller pieces that can be scheduled to run on any executor on any agent in the cluster. Once a node block completes, Jenkins serializes the remaining variables to pass on to the next node block or to the intervening Groovy code.

Theoretically, this works seamlessly and is a great feature. And it does, when all the classes used in your script are serializable.

I’ve been bitten by using non-serializable classes multiple times during pipeline script development. I’ve also had scripts start failing after a Jenkins server upgrade that forced installation of a new Java version and classes that were once serializable lost the ability to be serialized.

Source