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

Loop HashMap and pass Dynamic Keys to Shell or bat script

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Minor Minor
    • pipeline
    • None

      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
      

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

              Created:
              Updated: