Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-66778

Loop HashMap and pass Dynamic Keys to Shell or bat script

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: pipeline
    • Labels:
      None
    • Similar Issues:

      Description

      I have small code,

      Which loops on Array and pass its element to shell script :- Works Fine

      Where If I have HashMap and after loops I am passing Keys to Shell script or bat or Powershell it throws and error  Why ?

       

      // 
      stage('Validation'){
              steps{
                  script{ 
                      test1 = ["elem1","elem2"]
                      test2 = [key1:"value1", key2:"value2"]
                                         
                      for(defaults in test1){
                          test=defaults
                          echo "before shell====> ${test}"
                          status = sh(returnStdout: true,  script: """
                              echo "${test}"
                          """).trim() 
                      }
                      echo "======started next HashMAP loop==========="
                      for(defaults in test2){
                          test=defaults.key
                          echo "before shell====> ${test}"
                          status = sh(returnStdout: true,  script: """
                              echo "${test}"
                          """).trim() 
                      }
                }
           }
       }
      

      Now Output is :

       

       

      Lastly in HashMap Loop I see this error, What Can be the fix ??:

      Caused: java.io.NotSerializableException: java.util.LinkedHashMap$Entry
      

        Attachments

          Activity

          There are no comments yet on this issue.

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ganeshw Ganesh Wankhede
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: