java.io.NotSerializableException: hudson.model.FreeStyleProject
<p>I am trying to execute pipeline script in Jenkins.
Here is my script:</p>

<pre><code>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')]];

}
</code></pre>

<p>But I am constantly getting NotSerializableException. I guess, something wrong in my getJobVariable method. Please, help </p>