Java.io.NotSerializableException: hudson.model.FreeStyleProject

I am trying to execute a script pipeline 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 constantly get a NotSerializableException. I think something is wrong in my getJobVariable method. Please, help

+4
source share
2 answers

I did some tests because I have the same problem in my pipeline jobs (for Matrix).

The decision should put defbefore jobor the name of the object (here job) before the declaration.

After the disappearance NotSerializableException.

, @NonCPS . . : serializing-local-variables.

+5

:

job = null after newJob = job.getLastBuild()
0

All Articles