Issue
A pipeline always ends with a java.io.NotSerializableException
, even if the result is the expected one.
Environment
- CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
- CloudBees CI (CloudBees Core) on traditional platforms - Client controller
- CloudBees Jenkins Enterprise - Managed controller
- CloudBees Jenkins Platform - Client controller
- CloudBees Jenkins Distribution
- Jenkins LTS
Resolution
By design a 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 extract 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