I am trying to execute pipeline script in Jenkins. Here is my script:
import com.cloudbees.groovy.cps.NonCPS
@NonCPS
def getJobVariable(jobName,varName){
job = Jenkins.instance.getItemByFullName(jobName)
newJob = job.getLastBuild()
return newJob.getEnvVars().get(varName,null)
}
node{
stage 'props'
api = build job: 'Props'
buildID = api.getNumber()
build job: 'Parameterized', parameters: [[$class: 'StringParameterValue', name: 'string_parameter', value: getJobVariable('Props','filename')]];
}
But I am constantly getting NotSerializableException. I guess, something wrong in my getJobVariable method. Please, help
His main interests include distributed systems, storage systems, file systems, and operating systems. In this tutorial we will discuss about NotSerializableException in Java. The exception is thrown when an instance of a class must implement the Serializable interface.
The simplest solution is to find the class that throws the exception and make it implement the Serializable interface. However, this may not be feasible if the class that throws the exception belongs to a third-party library.
The SerializableClass implements the Serializable interface, but it refers to the Pair class which doesn’t. The simplest solution is to find the class that throws the exception and make it implement the Serializable interface. However, this may not be feasible if the class that throws the exception belongs to a third-party library.
AbstractModelObject Methods inherited from interface hudson.model. Item Methods inherited from interface hudson.model. PersistenceRoot Methods inherited from interface hudson.search. SearchableModelObject Methods inherited from interface hudson.search. SearchItem Methods inherited from interface hudson.security. AccessControlled
I've made some tests, cause I've the same issue in my pipeline jobs (for Matrix).
The solution is to put def
before job
or the name of Object (here Job
) before your declaration.
After the NotSerializableException
disappear.
If this does not solve your problem, you can also add @NonCPS
flag before your declaration. See the official documentation: serializing-local-variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With