-1

In my master pipeline job i have set of values , and with each values I need to trigger another job

  def map = [FRA1: "192.168.1.1", DEL: "192.168.1.2", NYC: "192.168.1.3"]
     for (element in map) {
                echo "${element.key} ${element.value}"
                stage("Triggering another job- ${element.key}")            
                build job: 'testjobcheck', parameters: [string(name: 'DC-NAME', value: 
                "${element.value}")
                 ]
              }

but getting the below exception

an exception which occurred:
    in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
    in object com.cloudbees.groovy.cps.impl.LoopBlockScopeEnv@71f4bf38
    in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
    in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@2a24a0f
    in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
    in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@5863a030
    in field com.cloudbees.groovy.cps.impl.CpsClosureDef.capture
    in object com.cloudbees.groovy.cps.impl.CpsClosureDef@df1925c
    in field com.cloudbees.groovy.cps.impl.CpsClosure.def
    in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@4ab0695
    in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
    in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@107c4dba
    in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@107c4dba
Caused: java.io.NotSerializableException: java.util.LinkedHashMap$Entry
    
    

can anyone help here?

Deepak
  • 11
  • 3

1 Answers1

0

See JENKINS-49732. There is a serialization failure for java.util.LinkedHashMap$Entry when the pipeline is trying to save (serialize) the current state.

As a workaround you can use:

def map = [FRA1: "192.168.1.1", DEL: "192.168.1.2", NYC: "192.168.1.3"]
map.each { key, value ->
    echo "${key} ${value}"
    stage("Triggering another job- ${key}"){           
       build job: 'testjobcheck', parameters: [string(name: 'DC-NAME',value: "${value}")]
    }
}

Small thing: when using the stage block use it with {} as using the ‘stage’ step without a block argument is deprecated.

Noam Helmer
  • 5,310
  • 1
  • 9
  • 29
  • Thanks for the input , getting the below exception now [Pipeline] echo FRA1 192.168.1.1 [Pipeline] End of Pipeline hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: element for class: WorkflowScript at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458) at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39) – Deepak Jun 28 '21 at 14:03
  • sorry my bad when using `each` on a map the iteration variables should be defined. i updated the answer with the correct format. – Noam Helmer Jun 28 '21 at 14:12
  • Thanks a lot it worked , much appreciated. One followup doubt , 1: is there any way i can run the jobs under for loop parallel..?. 2: And change the status of each stage if the job is failure/success – Deepak Jun 28 '21 at 14:28
  • Check out [This Question](https://stackoverflow.com/questions/46834998/scripted-jenkinsfile-parallel-stage/53456430) for more info. if you need something more specific ask a new questions as it is not possible to add code blocks in comments – Noam Helmer Jun 28 '21 at 15:34