I have a very simple pipeline that malfunctions unexpectedly.  Adding @NonCPS 
decorators also does not workaround the job failure problem, so I'm mystified 
as to how to write this correctly.  I'm not sure if there is a coding error in 
the pipeline libs, a coding error in our local lib, or a simpler means of doing 
what I really need.  What is really weird is that the intended operation seems 
to work, but fails the job with a surprise serialization traceback!  Bug or 
what?

The problem is simple: discover the build number of a separate project feeder 
job and use that in the current pipeline.


1) Simple pipeline job (Takes a parameter, prints it out)



Takes a String parameter PARAM1



Pipeline definition:



println PARAM1



2) Global library ("jenkins-common", defined in our Jenkins configuration)



#!/usr/bin/groovy

// Pass in "buildJob"
// If the job is a multi-branch, pass in "branch" as well
// -1 indicates that we could not determine the last successful build number
def call(body) {
  // evaluate the body block, and collect configuration into the object
  def config = [:]
  body.resolveStrategy = Closure.DELEGATE_FIRST
  body.delegate = config
  body()

  // See http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html
  jenkins = jenkins.model.Jenkins.getInstance()
  job = jenkins.getItemByFullName(config.buildJob)
  def build = null

  if (job instanceof org.jenkinsci.plugins.workflow.job.WorkflowJob) {
    build = job.getLastSuccessfulBuild()
  } else if (job instanceof 
org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) {
    build = job.getBranch(config.branch).getLastSuccessfulBuild()
  }

  if (null != build) {
    result = build.getResult()
    return (result == hudson.model.Result.SUCCESS) ? build.getNumber() : -1
  } else {
    return -1
  }
}



3) Main job (Figure out any job's last successful build number and pass it to 
another job)



@Library("jenkins-common")

@NonCPS
def getBuild(def name) {
  return lastSuccessfulBuildnumber {
    buildJob = name
    branch = "master"
  }
}
int awsBuild = getBuild("/CDS/AWS Cloudtrail")



// The following will yield the same result

// def awsBuild = lastSuccessfulBuildnumber {
//    buildJob = name
//    branch = "master"
//  }


  build job: '.Test/Print parameter', propagate: false, parameters: [
    [$class: 'StringParameterValue', name: 'PARAM1', value: "${awsBuild}"]
  ]



3b) This works just fine



int awsBuild = 123



build job: '.Test/Print parameter', propagate: false, parameters: [
    [$class: 'StringParameterValue', name: 'PARAM1', value: "${awsBuild}"]
  ]



4) Kicking off job 3 will result in a failure. But, it will properly kick off 
the "print parameter" job!



5) Console output from print parameter



Started by upstream project "Main job" build number 50

originally caused by:

 Started by user xxxx

 Replayed #49

[Pipeline] echo

2

[Pipeline] End of Pipeline

Finished: SUCCESS





6) Console output from main job



Started by user xxxx

Replayed #50

Loading library jenkins-common@master

 > git rev-parse --is-inside-work-tree # timeout=10

Setting origin to ssh://gerrit:29418/jenkins/common.git

 > git config remote.origin.url ssh://gerrit:29418/jenkins/common.git # 
 > timeout=10

Fetching origin...

Fetching upstream changes from origin

 > git --version # timeout=10

using GIT_SSH to set credentials ssh key access

 > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*

 > git rev-parse master^{commit} # timeout=10

 > git rev-parse origin/master^{commit} # timeout=10

 > git rev-parse --is-inside-work-tree # timeout=10

Fetching changes from the remote Git repository

 > git config remote.origin.url ssh://gerrit:29418/jenkins/common.git # 
 > timeout=10

Fetching upstream changes from ssh://gerrit:29418/jenkins/common.git

 > git --version # timeout=10

using GIT_SSH to set credentials ssh key access

 > git fetch --tags --progress ssh://gerrit:29418/jenkins/common.git 
 > +refs/heads/*:refs/remotes/origin/*

Checking out Revision 69ab6e9be3a8afd0a847d29d60c4b6ad320ca2f1 (master)

 > git config core.sparsecheckout # timeout=10

 > git checkout -f 69ab6e9be3a8afd0a847d29d60c4b6ad320ca2f1

 > git rev-list 69ab6e9be3a8afd0a847d29d60c4b6ad320ca2f1 # timeout=10

[Pipeline] build (Building .Test > Print parameter)

Scheduling project: .Test > Print parameter

[Pipeline] End of Pipeline

java.io.NotSerializableException: hudson.model.Hudson

        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)

        at java.util.HashMap.writeObject(HashMap.java:1362)

        at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)

        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:498)

        at 
org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:271)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)

        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 
com.cloudbees.groovy.cps.SerializableScript.writeObject(SerializableScript.java:26)

        at sun.reflect.GeneratedMethodAccessor531.invoke(Unknown Source)

        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:498)

        at 
org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:271)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)

        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)

        at java.util.HashMap.writeObject(HashMap.java:1362)

        at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)

        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:498)

        at 
org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:271)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)

        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 
com.cloudbees.groovy.cps.SerializableScript.writeObject(SerializableScript.java:26)

        at sun.reflect.GeneratedMethodAccessor531.invoke(Unknown Source)

        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:498)

        at 
org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:271)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:569)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)

        at 
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)

        at 
org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)

        at 
org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)

        at 
org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.writeObject(RiverWriter.java:132)

        at 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:453)

        at 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:427)

        at 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:415)

        at 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:360)

        at 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:80)

        at 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:240)

        at 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:228)

        at 
org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)

        at java.util.concurrent.FutureTask.run(FutureTask.java:266)

        at 
hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)

        at 
jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)

        at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

        at java.util.concurrent.FutureTask.run(FutureTask.java:266)

        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

        at java.lang.Thread.run(Thread.java:745)

Caused by: an exception which occurred:

        in field scripts

        in object 
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@4cc8e583<mailto:org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@4cc8e583>

Finished: FAILURE


-- 
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/2eddaa4b2a18449cb055313eccc176fc%40mbx02cmb01p.esentire.local.
For more options, visit https://groups.google.com/d/optout.

Reply via email to