Sviatlana Sviatlana - 2 months ago 24
Groovy Question

java.io.NotSerializableException: hudson.model.FreeStyleProject

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

Answer

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.

Comments