运行Java Groovy脚本并更新到最新的Groovy管道时。谢谢你的帮助。
我发现此错误是一个异常:在字段中的字段本地调用者在字段e中的字段程序中对象org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@3123aac2中的字段线程中引发:java.io.NotSerializableException: hudson.model.Run $神器 我认为有问题的代码是
stage('Retrieve Code') {
FileCacheCountCheck();
def job = jenkins.model.Jenkins.instance.getItem("pipeline.preview.build")
def build = job.getBuildByNumber(buildNumber)
def art = build.artifacts[0]
def file = art.file
def targetPath = pwd()
"rm -rf ${targetPath}/output".execute().text
"rm -rf ${targetPath}/script".execute().text
touch file: "${targetPath}/output/package.tmp"
"cp ${file} ${targetPath}/output/package.zip".execute().text
"cp -R ${targetPath}@script/ ${targetPath}/script/".execute().text
}
stage('Stash Package') {
def targetPath = pwd() 藏匿包括:'输出/ **',名称:'包'
根据这篇文章,https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md#serializing-local-variables我尝试使用
@NonCPS
stage('Retrieve Code') {
FileCacheCountCheck();
@NonCPS
def job = jenkins.model.Jenkins.instance.getItem("pipeline.preview.build")
@NonCPS
def build = job.getBuildByNumber(buildNumber)
@NonCPS
def art = build.artifacts[0]
@NonCPS
def file = art.file
@NonCPS
def targetPath = pwd()
"rm -rf ${targetPath}/output".execute().text
"rm -rf ${targetPath}/script".execute().text
touch file: "${targetPath}/output/package.tmp"
"cp ${file} ${targetPath}/output/package.zip".execute().text
"cp -R ${targetPath}@script/ ${targetPath}/script/".execute().text
}
stage('Stash Package') {
@NonCPS
def targetPath = pwd()
stash includes: 'output/**', name: 'package'
}
这是整个堆栈跟踪 发生的异常:在字段中的字段本地调用者字段e中的字段程序在字段中的字段中 org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@3123aac2引起:java.io.NotSerializableException:hudson.model.Run $神器在org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)的组织。 jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)在org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)在org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java: 50)在org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)在java.io.ObjectOutputStream.writeObject(未知来源)在java.util.HashMap.internalWriteEntries(未知来源)在java.util中。 HashMap.writeObject(来源不明)在sun.reflect.GeneratedMethodAccessor74.invoke(来源不明)在sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明)在java.lang.reflect.Method.invoke(来源不明)在org.jboss。 marshalling.reflect.SerializableCla ss.callWriteObject(SerializableClass.java:271)在org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)在org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)在组织.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)位于org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller的.java:854)在org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)在org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)在org.jboss.marshalling。 river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)在org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)在org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)在org.jboss.marshalling.river.R iverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)在org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)在org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)在组织.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)在org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)在org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller .java:854)org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)at org.jboss.marshalling。 MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)在org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)在java.io.ObjectOutputStream.writeObject(来源不明)在java.util.TreeMap.wri teObject(未知来源)在sun.reflect.GeneratedMethodAccessor272.invoke(未知来源)在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)在java.lang.reflect.Method.invoke(未知来源)在org.jboss.marshalling。 reflect.SerializableClass.callWriteObject(SerializableClass.java:271)在org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)在org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)在org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)在org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)在org.jboss.marshalling.river.RiverMarshaller.doWriteObject (RiverMarshaller.java:854)在org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)在org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)在org.jenkinsci.plugins.workflow。 support.pickles.serialization。 RiverWriter.writeObject(RiverWriter.java:140)在org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:458)在org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java: 434)在org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:422)在org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:362)在org.jenkinsci.plugins位于org.jenkinsci.plugins.workflow.cps.CpsThreadGroup的org.jenkinsci.plugins.workflow.cps.CpsThreadGroup $ 2.call(CpsThreadGroup.java:242)上的.workflow.cps.CpsThreadGroup.access $ 100(CpsThreadGroup.java:82)位于hudson.remoting的java.util.concurrent.FutureTask.run(未知来源)的org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService $ 2.call(CpsVmExecutorService.java:64)$ 2.call(CpsThreadGroup.java:230) .SingleLaneExecutorService $ 1.run(SingleLaneExecutorService.java:112)at jenkins.util.ContextResettingExecutorService $ 1.run(ContextResettingExecutorService.java:28)a t java.util.concurrent.coneurrent上的java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)java.util.concurrent.FutureTask.run(未知来源)的java.util.concurrent.Executors $ RunnableAdapter.call(未知来源) java.lang.Thread.run上的.ThreadPoolExecutor $ Worker.run(未知来源)(未知来源)完成:失败
答案 0 :(得分:0)
根据article:最安全的方法是在标注注释@NonCPS的方法中隔离非可序列化状态的使用
只需声明一个函数并将不可序列化的调用/步骤放入其中
@NonCPS --- Once I removed this it worked. Also had to pass buildnumber as a parameter
def getArtifactPath(){
def job = jenkins.model.Jenkins.instance.getItem("pipeline.preview.build")
def build = job.getBuildByNumber(buildNumber)
def art = build.artifacts[0]
return art.file
}
并将此功能称为您的一个阶段步骤。