Issue
The pipeline always ends with a java.io.NotSerializableException
, even if I can have the expected result.
Environment
- Jenkins 1.580+
- Pipeline 1.0+
Resolution
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
. For example, you need to transform
def job = Jenkins.instance.getItemByFullName('test')
def sourceBuild = job.getLastBuild().getNumber()
into
@NonCPS
def getBuildNumber(String jobName) {
def job = Jenkins.instance.getItemByFullName(jobName)
return job.getLastBuild().getNumber()
}
def build = getBuildNumber('test')
0 Comments