Hello All,

I have tested the below snippet of code in myjenkinsurl/script and it works 
fine.

However, same code (embedded or loaded via external Groovy code) in 
Pipeline workflow script fails, inspite of CPS annotation (with the 
stacktrace that's given after this code snippet) ?

NOTE:
First print statement in 'getjobName' function successfully matches the job 
(using regex).

#!/usr/bin/env groovy

import org.jenkinsci.plugins.workflow.job.*

@NonCPS
def getjobName(String job) {
    for (item in Jenkins.instance.items) {
        if (item =~ /metamon-alert-configs/ ) {
            println item.getName()
            jobname = item
        }
    }
    
    for (build in jobname.Builds()) {
        println build
    }
}


node('master') {
    stage('getlog') {
        def jobname = getjobName("mon-alert-configs")
    }
}


Reading (novice at it) the stacktrace suggests it's to do with 
serialization of variables but the annotation should take care of that, 
isn't it ?

an exception which occurred:
        in field groovy.lang.Closure.delegate
        in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@72ae419a
        in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
        in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@401a5d46
        in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@401a5d46
Caused: java.io.NotSerializableException: 
org.jenkinsci.plugins.workflow.job.WorkflowJob
        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
        at 
org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
        at 
org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
        at 
org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
        at 
org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
        at java.util.LinkedHashMap.internalWriteEntries(LinkedHashMap.java:333)
. . . . . 
. . . . .


/Ram

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/68199c67-9ccf-42e2-8bf3-f38fe4708350%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to