• Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • pipeline
    • Jenkins 2.289.2

      Hi Team,

      We are trying to get the value from rest API and assign that value to variable to access on other stages, this stage running and we are getting desired value but stage is showing as failed and other stages are not executing, previosuly it was working but suddenly it is started failing, please find the stage defination below.

      stage('Get build number') {
                  steps {
                      script {
                          try {
                               NirvanaCC = "\Clearcase View Profiles\E1T_OWA\Staging\Enhancements"
                               echo "CC is: ${NirvanaCC}"
                               def sout = new StringBuffer(), serr = new StringBuffer()
                               def val1 = NirvanaCC.tokenize( '\\' )
                               echo "val1 is: ${val1}"
                               def val2 = val1[3..-1]
                               echo "val2 is: ${val2}"
                               def val3 = val2.last()
                               echo "val3 is: ${val3}"
                               def val4 = val3.substring(0, val3.length() - 1)
                               echo "val4 is: ${val4}"
                               def val5 = val2.remove(val2.size() -1)
                               echo "val5 is: ${val5}"
                               def val6 = val2 << val4
                               echo "val6 is: ${val6}"
                               def branch = val6.join('\\')
                               echo "branch is: ${val6}"
                               def proc = "curl -v -G --data ccbranch=${branch} -k https://apex.oraclecorp.com/pls/apex/jdedevops/nirvanabuild/next".execute()
                               echo "Responce is: ${proc}"
                               proc.consumeProcessOutput(sout, serr)
                               proc.waitForOrKill(6000)
                               def x = sout.tokenize()
                               echo "sout is: ${x}"
                               JsonSlurper slurper = new JsonSlurper()
                               parsedJson = slurper.parseText(x)
                               def nextbuild = [parsedJson.next_buildid]
                               NirvanaClearCaseLabelName = nextbuild[0]
                               echo "NirvanaClearCaseLabelName is: $NirvanaClearCaseLabelName"
                               NirvanaProductVersion = nextbuild[0]
                               echo "NirvanaProductVersion is: $NirvanaProductVersion"
                              
                          } catch (Exception e) {
                              echo 'Exception occurred: ' + e.toString()
            
                           }
                             
                          }
                     }
              }
      

      This is the error message I am getting at the end of the pipeline
      [Pipeline] End of Pipelinean exception which occurred:
      in field org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptScript.script
      in object org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.LabelScript@63b53ff
      in field groovy.lang.Closure.delegate
      in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@397359e1
      in field groovy.lang.Closure.delegate
      in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@28960361
      in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
      in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@649a893f
      in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@649a893f
      Caused: java.io.NotSerializableException: groovy.json.internal.LazyMap
      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:926)
      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:1363)
      at sun.reflect.GeneratedMethodAccessor100.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.JDKSpecific$SerMethods.callWriteObject(JDKSpecific.java:156)
      at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:191)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1028)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
      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.GeneratedMethodAccessor382.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.JDKSpecific$SerMethods.callWriteObject(JDKSpecific.java:156)
      at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:191)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1028)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
      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:1793)
      at java.util.HashMap.writeObject(HashMap.java:1363)
      at sun.reflect.GeneratedMethodAccessor100.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.JDKSpecific$SerMethods.callWriteObject(JDKSpecific.java:156)
      at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:191)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1028)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
      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.lambda$writeObject$0(RiverWriter.java:144)
      at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:237)
      at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.writeObject(RiverWriter.java:143)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:557)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:534)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:517)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:441)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
      at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
      at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
      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:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
      Finished: FAILURE

          [JENKINS-68289] Groovy Script Success But Pipeline Stage fails

          This has a newline within a single-quoted string:

          def val1 = NirvanaCC.tokenize( '
          ' )
          

          I don't think that's supported in Groovy. Use '\n' or a triple-single-quoted string instead.

          However, Jira lost the indentation from your script and replaced some characters, so I can't be sure the above is what you're actually using in Jenkins. Please edit the description, select the "Text" mode rather than "Visual", replace the script with the original version, and add {noformat} lines above and below the script. That will prevent Jira from changing the formatting. See Advanced Formatting for an example.

          I suggest moving the version computation, REST API call, and parsing logic from the pipeline to a separate script file, e.g. in Python, and then using the sh step to run it. That would let it be debugged without Jenkins, and would shift some load from the Jenkins controller to the agent. If you need to set the NirvanaClearCaseLabelName and NirvanaProductVersion variables at the Jenkins side, you can make the Python script write those values to files that the Jenkins pipeline then reads using readFile steps.

          Kalle Niemitalo added a comment - This has a newline within a single-quoted string : def val1 = NirvanaCC.tokenize( ' ' ) I don't think that's supported in Groovy. Use '\n' or a triple-single-quoted string instead. However, Jira lost the indentation from your script and replaced some characters, so I can't be sure the above is what you're actually using in Jenkins. Please edit the description, select the "Text" mode rather than "Visual", replace the script with the original version, and add {noformat} lines above and below the script. That will prevent Jira from changing the formatting. See Advanced Formatting for an example. I suggest moving the version computation, REST API call, and parsing logic from the pipeline to a separate script file, e.g. in Python, and then using the sh step to run it. That would let it be debugged without Jenkins, and would shift some load from the Jenkins controller to the agent. If you need to set the NirvanaClearCaseLabelName and NirvanaProductVersion variables at the Jenkins side, you can make the Python script write those values to files that the Jenkins pipeline then reads using readFile steps.

          stage('Get build number') {
                      steps {
                          script {
                              try {
                                   NirvanaCC = "${params.NirvanaClearCaseViewProfile}"
                                   echo "CC is: ${NirvanaCC}"
                                   def sout = new StringBuffer(), serr = new StringBuffer()
                                   def val1 = NirvanaCC.tokenize( '\\' )
                                   echo "val1 is: ${val1}"
                                   def val2 = val1[3..-1]
                                   echo "val2 is: ${val2}"
                                   def val3 = val2.last()
                                   echo "val3 is: ${val3}"
                                   def val4 = val3.substring(0, val3.length() - 1)
                                   echo "val4 is: ${val4}"
                                   def val5 = val2.remove(val2.size() -1)
                                   echo "val5 is: ${val5}"
                                   def val6 = val2 << val4
                                   echo "val6 is: ${val6}"
                                   def branch = val6.join('\\')
                                   echo "branch is: ${val6}"
                                   def proc = "curl -v -G --data ccbranch=${branch} -k https://apex.oraclecorp.com/pls/apex/jdedevops/nirvanabuild/next".execute()
                                   echo "Responce is: ${proc}"
                                   proc.consumeProcessOutput(sout, serr)
                                   proc.waitForOrKill(6000)
                                   def x = sout.tokenize()
                                   echo "sout is: ${x}"
                                   JsonSlurper slurper = new JsonSlurper()
                                   parsedJson = slurper.parseText(x)
                                   def nextbuild = [parsedJson.next_buildid]
                                   NirvanaClearCaseLabelName = nextbuild[0]
                                   echo "NirvanaClearCaseLabelName is: $NirvanaClearCaseLabelName"
                                   NirvanaProductVersion = nextbuild[0]
                                   echo "NirvanaProductVersion is: $NirvanaProductVersion"
                                  
                              } catch (Exception e) {
                                  echo 'Exception occurred: ' + e.toString()
                
                               }
                                 
                              }
                         }
                  }
          

          Satish Yandamuri added a comment - stage('Get build number') { steps { script { try { NirvanaCC = "${params.NirvanaClearCaseViewProfile}" echo "CC is: ${NirvanaCC}" def sout = new StringBuffer(), serr = new StringBuffer() def val1 = NirvanaCC.tokenize( '\\' ) echo "val1 is: ${val1}" def val2 = val1[3..-1] echo "val2 is: ${val2}" def val3 = val2.last() echo "val3 is: ${val3}" def val4 = val3.substring(0, val3.length() - 1) echo "val4 is: ${val4}" def val5 = val2.remove(val2.size() -1) echo "val5 is: ${val5}" def val6 = val2 << val4 echo "val6 is: ${val6}" def branch = val6.join('\\') echo "branch is: ${val6}" def proc = "curl -v -G --data ccbranch=${branch} -k https://apex.oraclecorp.com/pls/apex/jdedevops/nirvanabuild/next".execute() echo "Responce is: ${proc}" proc.consumeProcessOutput(sout, serr) proc.waitForOrKill(6000) def x = sout.tokenize() echo "sout is: ${x}" JsonSlurper slurper = new JsonSlurper() parsedJson = slurper.parseText(x) def nextbuild = [parsedJson.next_buildid] NirvanaClearCaseLabelName = nextbuild[0] echo "NirvanaClearCaseLabelName is: $NirvanaClearCaseLabelName" NirvanaProductVersion = nextbuild[0] echo "NirvanaProductVersion is: $NirvanaProductVersion" } catch (Exception e) { echo 'Exception occurred: ' + e.toString() } } } }

          Hi Kalle Niemitalo,

          Thank you for your reply, I have formated the code, the same code worked a few months back without any issue, Jenkins able to get the values from rest API and parsed them and able to access those values to next step, now there is no change in pipeline code and Jenkins version but pipeline step is failing.

          Regards,
          Satish

          Satish Yandamuri added a comment - Hi Kalle Niemitalo, Thank you for your reply, I have formated the code, the same code worked a few months back without any issue, Jenkins able to get the values from rest API and parsed them and able to access those values to next step, now there is no change in pipeline code and Jenkins version but pipeline step is failing. Regards, Satish

          Kalle Niemitalo added a comment - - edited

          JsonSlurper.parseText returns "a data structure of lists and maps". Perhaps that means groovy.json.internal.LazyMap, which then is not serializable.

          If you want to keep doing this parsing in the pipeline script, try moving it to a method annotated with @NonCPS as described in Pipeline Best Practices and Pipeline CPS Method Mismatches. That way, Jenkins won't try to serialize the map.

          Kalle Niemitalo added a comment - - edited JsonSlurper.parseText returns "a data structure of lists and maps". Perhaps that means groovy.json.internal.LazyMap, which then is not serializable. If you want to keep doing this parsing in the pipeline script, try moving it to a method annotated with @NonCPS as described in Pipeline Best Practices and Pipeline CPS Method Mismatches . That way, Jenkins won't try to serialize the map.

          Might there have been a change in the pipeline durability setting (JENKINS-47300, https://github.com/jenkinsci/workflow-api-plugin/pull/55)?

          Kalle Niemitalo added a comment - Might there have been a change in the pipeline durability setting ( JENKINS-47300 , https://github.com/jenkinsci/workflow-api-plugin/pull/55 )?

          Hi Kalle Niemitalo,

          Could you please help me to write this step using @NonCPS, my API out put will be [

          {"next_buildid":"ENH_9.2.6.04.08"}

          ], from here I want to get the ENH_9.2.6.04.08 and assign to a variable to consume on next steps in pipeline. I tried to change the pipeline durability setting but it did not help me, I tried to read the best practices of Jenkins pipeline but I am not sure how we can write pipeline step using @NonCPS method.

          Satish Yandamuri added a comment - Hi Kalle Niemitalo, Could you please help me to write this step using @NonCPS, my API out put will be [ {"next_buildid":"ENH_9.2.6.04.08"} ], from here I want to get the ENH_9.2.6.04.08 and assign to a variable to consume on next steps in pipeline. I tried to change the pipeline durability setting but it did not help me, I tried to read the best practices of Jenkins pipeline but I am not sure how we can write pipeline step using @NonCPS method.

          Could perhaps put the whole thing in @NonCPS

          pipeline {
              // agent and other declarations
          
              stages {
                  stage('Get build number') {
                      steps {
                          script {
                              try {
                                  // Call the method that has the @NonCPS annotation.
                                  // It returns an array of strings.  Destructure the array to variables.
                                  [NirvanaClearCaseLabelName, NirvanaProductVersion] = getBuildNumber(branch)
                              } catch (Exception e) {
                                  echo 'Exception occurred: ' + e.toString()
                              }
                          }
                      }
                  }
              }
          }
          
          // Define the method that is called from the pipeline.
          // This has the @NonCPS annotation, so the values of local variables
          // do not need to be serializable.
          @NonCPS
          String[] getBuildNumber(String branch) {
              NirvanaCC = "\Clearcase View Profiles\E1T_OWA\Staging\Enhancements"
          
              // In general, you cannot call pipeline steps from a method annotated with @NonCPS.
              // The echo step is a bit special; I think it will work, but I don't remember seeing
              // any documentation that actually promises it will work.
              echo "CC is: ${NirvanaCC}"
          
              def sout = new StringBuffer(), serr = new StringBuffer()
              def val1 = NirvanaCC.tokenize( '\\' )
              echo "val1 is: ${val1}"
              def val2 = val1[3..-1]
              echo "val2 is: ${val2}"
              def val3 = val2.last()
              echo "val3 is: ${val3}"
              def val4 = val3.substring(0, val3.length() - 1)
              echo "val4 is: ${val4}"
              def val5 = val2.remove(val2.size() -1)
              echo "val5 is: ${val5}"
              def val6 = val2 << val4
              echo "val6 is: ${val6}"
              def branch = val6.join('\\')
              echo "branch is: ${val6}"
              def proc = "curl -v -G --data ccbranch=${branch} -k https://apex.oraclecorp.com/pls/apex/jdedevops/nirvanabuild/next".execute()
              echo "Responce is: ${proc}"
              proc.consumeProcessOutput(sout, serr)
              proc.waitForOrKill(6000)
              def x = sout.tokenize()
              echo "sout is: ${x}"
              JsonSlurper slurper = new JsonSlurper()
              parsedJson = slurper.parseText(x)
              def nextbuild = [parsedJson.next_buildid]
          
              // I'm not sure how you're going to use the NirvanaClearCaseLabelName
              // and NirvanaProductVersion variables in the rest of the pipeline,
              // or whether it is possible to set pipeline global variables from @NonCPS.
              // To be safe, put these in locals instead, and return the values to the caller,
              // which can then assign them where it wants.
              def NirvanaClearCaseLabelName = nextbuild[0]
              echo "NirvanaClearCaseLabelName is: $NirvanaClearCaseLabelName"
              def NirvanaProductVersion = nextbuild[0]
              echo "NirvanaProductVersion is: $NirvanaProductVersion"
              return [NirvanaClearCaseLabelName, NirvanaProductVersion]
          }
          

          Kalle Niemitalo added a comment - Could perhaps put the whole thing in @NonCPS pipeline { // agent and other declarations stages { stage( 'Get build number' ) { steps { script { try { // Call the method that has the @NonCPS annotation. // It returns an array of strings. Destructure the array to variables. [NirvanaClearCaseLabelName, NirvanaProductVersion] = getBuildNumber(branch) } catch (Exception e) { echo 'Exception occurred: ' + e.toString() } } } } } } // Define the method that is called from the pipeline. // This has the @NonCPS annotation, so the values of local variables // do not need to be serializable. @NonCPS String [] getBuildNumber( String branch) { NirvanaCC = "\Clearcase View Profiles\E1T_OWA\Staging\Enhancements" // In general, you cannot call pipeline steps from a method annotated with @NonCPS. // The echo step is a bit special; I think it will work, but I don't remember seeing // any documentation that actually promises it will work. echo "CC is: ${NirvanaCC}" def sout = new StringBuffer (), serr = new StringBuffer () def val1 = NirvanaCC.tokenize( '\\' ) echo "val1 is: ${val1}" def val2 = val1[3..-1] echo "val2 is: ${val2}" def val3 = val2.last() echo "val3 is: ${val3}" def val4 = val3.substring(0, val3.length() - 1) echo "val4 is: ${val4}" def val5 = val2.remove(val2.size() -1) echo "val5 is: ${val5}" def val6 = val2 << val4 echo "val6 is: ${val6}" def branch = val6.join( '\\' ) echo "branch is: ${val6}" def proc = "curl -v -G --data ccbranch=${branch} -k https: //apex.oraclecorp.com/pls/apex/jdedevops/nirvanabuild/next" .execute() echo "Responce is: ${proc}" proc.consumeProcessOutput(sout, serr) proc.waitForOrKill(6000) def x = sout.tokenize() echo "sout is: ${x}" JsonSlurper slurper = new JsonSlurper() parsedJson = slurper.parseText(x) def nextbuild = [parsedJson.next_buildid] // I 'm not sure how you' re going to use the NirvanaClearCaseLabelName // and NirvanaProductVersion variables in the rest of the pipeline, // or whether it is possible to set pipeline global variables from @NonCPS. // To be safe, put these in locals instead, and return the values to the caller, // which can then assign them where it wants. def NirvanaClearCaseLabelName = nextbuild[0] echo "NirvanaClearCaseLabelName is: $NirvanaClearCaseLabelName" def NirvanaProductVersion = nextbuild[0] echo "NirvanaProductVersion is: $NirvanaProductVersion" return [NirvanaClearCaseLabelName, NirvanaProductVersion] }

          Hi Kalle Niemitalo,

          Thank you for your input, I will try to implement this and let you know

          Satish Yandamuri added a comment - Hi Kalle Niemitalo, Thank you for your input, I will try to implement this and let you know

          Satish Yandamuri added a comment - - edited

          Hi Kalle Niemitalo,

          This is what I created and working fine, but JsonSlurperClassic worked instaed of JsonSlurper, thank you verymuch for your help.

          @NonCPS
          String[] getNextBuildNumber(String branch1) {
              def NirvanaCC = branch1
              def sout = new StringBuffer(), serr = new StringBuffer()
              def val1 = NirvanaCC.tokenize( '\\' )
              def val2 = val1[3..-1]
              def val3 = val2.last()
              def val4 = val3.substring(0, val3.length() - 1)
              def val5 = val2.remove(val2.size() -1)
              def val6 = val2 << val4
              def branch = val6.join('\\')
              def proc = "curl -v -G --data ccbranch=${branch} -k https://apex.oraclecorp.com/pls/apex/jdedevops/nirvanabuild/next".execute()
              proc.consumeProcessOutput(sout, serr)
              proc.waitForOrKill(6000)
              def x = sout.tokenize()
              def jsonSlurper = new JsonSlurperClassic()
              parsedJson = jsonSlurper.parseText(x)
              def nextbuild = [parsedJson.next_buildid]
              return nextbuild
          }
          
          Pipeline stage:
          
          stage('Get NirvanaClearCaseLabelName and NirvanaProductVersion'){
                      when { expression { return params.Schedule } }
                      steps{
                          script{
                              try {
                                   buildinfo = getNextBuildNumber("${params.NirvanaClearCaseViewProfile}").join(" ")
                                   NirvanaClearCaseLabelName = "${buildinfo}"
                                   NirvanaProductVersion = "${buildinfo}"
                                   echo "NirvanaClearCaseLabelName is: ${NirvanaClearCaseLabelName}"
                                   echo "NirvanaProductVersion is: ${NirvanaProductVersion}"
                                  
                              } catch (Exception e) {
                                  echo 'Exception occurred: ' + e.toString()
                
                               }
                  }
              }
          }
          

          Satish Yandamuri added a comment - - edited Hi Kalle Niemitalo, This is what I created and working fine, but JsonSlurperClassic worked instaed of JsonSlurper, thank you verymuch for your help. @NonCPS String[] getNextBuildNumber(String branch1) { def NirvanaCC = branch1 def sout = new StringBuffer(), serr = new StringBuffer() def val1 = NirvanaCC.tokenize( '\\' ) def val2 = val1[3..-1] def val3 = val2.last() def val4 = val3.substring(0, val3.length() - 1) def val5 = val2.remove(val2.size() -1) def val6 = val2 << val4 def branch = val6.join('\\') def proc = "curl -v -G --data ccbranch=${branch} -k https://apex.oraclecorp.com/pls/apex/jdedevops/nirvanabuild/next".execute() proc.consumeProcessOutput(sout, serr) proc.waitForOrKill(6000) def x = sout.tokenize() def jsonSlurper = new JsonSlurperClassic() parsedJson = jsonSlurper.parseText(x) def nextbuild = [parsedJson.next_buildid] return nextbuild } Pipeline stage: stage('Get NirvanaClearCaseLabelName and NirvanaProductVersion'){ when { expression { return params.Schedule } } steps{ script{ try { buildinfo = getNextBuildNumber("${params.NirvanaClearCaseViewProfile}").join(" ") NirvanaClearCaseLabelName = "${buildinfo}" NirvanaProductVersion = "${buildinfo}" echo "NirvanaClearCaseLabelName is: ${NirvanaClearCaseLabelName}" echo "NirvanaProductVersion is: ${NirvanaProductVersion}" } catch (Exception e) { echo 'Exception occurred: ' + e.toString() } } } }

          I'm resolving this as Not A Defect, because the need for serializable types and the @NonCPS workaround are documented in https://www.jenkins.io/doc/book/pipeline/pipeline-best-practices/#avoiding-notserializableexception.

          Kalle Niemitalo added a comment - I'm resolving this as Not A Defect, because the need for serializable types and the @NonCPS workaround are documented in https://www.jenkins.io/doc/book/pipeline/pipeline-best-practices/#avoiding-notserializableexception .

            Unassigned Unassigned
            satishyandamuri Satish Yandamuri
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: