szabgab / code-maven.com

The content of the Code-Maven site
https://code-maven.com/
30 stars 54 forks source link

How to use map in jenkinsfile ? #175

Closed wangyu8460958 closed 1 year ago

wangyu8460958 commented 1 year ago

I write code in jenkinsfile


pipeline{

   agent { label "docker-slave2" }

   options {
       timestamps()
   }  

   stages {

       stage('parallel stage'){
           steps {
             script {
                def nodejsmap = [ "/home/tcl/customer": "sales-customer-ui-prod", "/home/tcl/platform": "sales-platform-ui-prod"  ]
                for  (element in nodejsmap) {
                      stage('Preparation') {
                       sh 'printenv'
                       cleanWs()
                       git branch: "${env.gitlabBranch}", credentialsId: "12345678", url: "http://172.16.200.112:8000/${element.value}.git"
                       }

                       stage('Build') {
                          nodejs('nodejs_16.16') {
                          sh 'npm install --location=global yarn'
                          sh 'yarn install'
                          sh 'rm -f package-lock.json'
                          sh 'npm run build:dev'
                          sh 'tar -zcvf dist/dist.tar dist/*' 
                          }
                        }

When I run this jenkinsfile , it report this error :

an exception which occurred:
    in field com.cloudbees.groovy.cps.impl.ForInLoopBlock$ContinuationImpl.itr
    in object com.cloudbees.groovy.cps.impl.ForInLoopBlock$ContinuationImpl@4d9df4d9
    in field com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.target
    in object com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl@1af3614
    in field com.cloudbees.groovy.cps.impl.SequenceBlock$ContinuationImpl.k
    in object com.cloudbees.groovy.cps.impl.SequenceBlock$ContinuationImpl@1cbb7b70

Caused: java.io.NotSerializableException: java.util.LinkedHashMap$LinkedEntryIterator
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:926)
    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.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.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)

How to solve the above problem ?

szabgab commented 1 year ago

I am sorry I don't have a Jenkins setup now and won't be able to help. I suggest you post this on StackOverflow.