2017-03-09 46 views
0

我在Jenkins管道中執行以下附加代碼。我得到以下錯誤 - java.io.NotSerializableException:java.security.MessageDigest $ Delegate。但是,當我爲流水線中的每個階段創建單獨的piepline項目時,它們運行時都沒有任何錯誤。例如,附加的詹金斯管道未能在階段「構建」之後調用階段「Execute Shell」。但是,當我將所有管道一起在單個管道中拼合成階段時。我無法做到這一點。

請求您幫助我解決問題。

Below is the Jenkins file: 


import java.security.*; 
import java.io.* 

node { 

    def mvnHome = tool 'M3' 
    git url: 'https://github.com/s88888/CDCD1.git' 
    def server = Artifactory.server 'Artifactory_Local' 

    stage "Build" 
    def uploadSpec_heatTemplate = readFile 'Test.yaml'  

    stage 'Execute Shell' 
    sh 'whoami' 

    // Get Artifactory server instance, defined in the Artifactory Plugin administration page. 


    stage 'Package Verify' 

     // Get Artifactory server instance, defined in the Artifactory Plugin administration page. 

     // Create the upload spec. 

     def uploadSpec1 = """{ 
      "files": [ 
        { 
         "pattern": "jenkins-pipeline-example/resources/ABC.zip", 
         "target": "libs-snapshot-local", 
         "props": "p1=v1;p2=v2" 
        } 
       ] 
      }""" 

     // Upload to Artifactory. 
     def buildInfo1 = server.upload spec: uploadSpec1 
     // Create the download spec. 
     def downloadSpec = """{ 
      "files": [ 
        { 
         "pattern": "libs-snapshot-local/*(ABC).zip", 
         "target": "test/", 
         "props": "p1=v1;p2=v2" 
        } 
       ] 
      }""" 

     // Download from Artifactory. 

     def buildInfo2 = server.download spec: downloadSpec 
     // Publish the build to Artifactory 
     server.publishBuildInfo buildInfo2 


    stage 'Final' 
    sh "echo 'Done with pipeline'" 


} 


Below is the error: 

Running on master in /var/lib/jenkins/workspace/E2EWorkflow 
[Pipeline] { 
[Pipeline] tool 
[Pipeline] stage (Build) 
Using the ‘stage’ step without a block argument is deprecated 
Entering stage Build 
Proceeding 
[Pipeline] readFile 
[Pipeline] echo 
f87ca3d668934f2f06c73ea70b5432d8 
[Pipeline] stage (Execute Shell) 
Using the ‘stage’ step without a block argument is deprecated 
Entering stage Execute Shell 
Proceeding 
[Pipeline] sh 
[E2EWorkflow] Running shell script 
[Pipeline] } 
[Pipeline] // node 
[Pipeline] End of Pipeline 
java.io.NotSerializableException: java.security.MessageDigest$Delegate 
    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.HashMap.internalWriteEntries(HashMap.java:1785) 
    at java.util.HashMap.writeObject(HashMap.java:1362) 
    at sun.reflect.GeneratedMethodAccessor35.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.doWriteObject(RiverMarshaller.java:854) 
    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.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032) 
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988) 
    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.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.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.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.TreeMap.writeObject(TreeMap.java:2438) 
    at sun.reflect.GeneratedMethodAccessor55.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.doWriteObject(RiverMarshaller.java:854) 
    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:452) 
    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 locals 
    in field caller 
    in field e 
    in field program 
    in field threads 
    in object [email protected] 
Finished: FAILURE 

回答

0

從管道頂端刪除不必要的import語句,它將起作用。

Pipeline中使用的所有代碼必須是可串行化的,並且您正在導入具有靜態初始化器的Java類,即使這些靜態初始器未使用也會導致問題。

你還應該注意的是你得到了「使用不帶塊參數中的‘舞臺’的步驟已過時」錯誤消息,並且使用正確的語法,例如:

// Correct 
stage('Build') { 
    … 
} 

// Deprecated 
stage 'Build' 
…