Sviatlana Sviatlana - 8 months ago 166
Groovy Question hudson.model.FreeStyleProject

I am trying to execute pipeline script in Jenkins.
Here is my script:

import com.cloudbees.groovy.cps.NonCPS
def getJobVariable(jobName,varName){
job = Jenkins.instance.getItemByFullName(jobName)
newJob = job.getLastBuild()
return newJob.getEnvVars().get(varName,null)

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


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.