shared library - hashmap error

124 views
Skip to first unread message

judaondo

unread,
Feb 17, 2020, 9:36:57 AM2/17/20
to Jenkins Users
Hello I have the following Shared Library:

#!/usr/bin/env groovy

import com.mycom.Logger

/**
 * Clone the selected git repository.
 *
 * Example usage within a declarative pipeline:
 *
 *    steps {
 *        gitCheckout (["htpp://myrepo1.git": "branch1", "htpp://myrepo2.git": "branch2"])
 *    }
 *
 * @param repositories (HashMap) git url and branch of the git project to be downloaded.
 */
def call(repositories = ["htpp://myrepo1.git""branch1""htpp://myrepo2.git""branch2"]) {
    def logger = new Logger()
    for (repo in repositories) {
        def repository = repo.key
        def branch = repo.value
        def foldername = repository.tokenize('/')[-1].toLowerCase()
        logger.info("Clonning '${repository} - (${branch} branch)' repository.")
        println("Foldername: " + foldername)
        println("Repository: " + repository)
        println("Branch: " + branch)
        checkout([$class: 'GitSCM', branches: [[name: branch]], 
                    doGenerateSubmoduleConfigurations: false
                    extensions: [
                        [$class: 'CloneOption', depth: 1, noTags: false, reference: '', shallow: true], 
                        [$class: 'RelativeTargetDirectory', relativeTargetDir: foldername]
                    ], 
                    submoduleCfg: [], 
                    userRemoteConfigs: [[credentialsId: 'gittfscredentials'
                                    url: repository]]])
    } // endfor

}


When using it in Jenkins pipeline 

#!/usr/bin/env groovy

@Library('mylib')

import com.mycom.*

pipeline {
    agent { label 'master' }

    options { 
        timestamps ()
        disableConcurrentBuilds()
    }

    stages {
        stage('Checkout') {
            steps {
                gitCheckoutMultipleRepositories()
            }   
        }
    }
    
}



I get the following error:


............
00:00:00.963  INFO: Clonning 'htpp://myrepo1.git - (branch1 branch)' repository.
[Pipeline] echo
00:00:00.972  Foldername: myrepo1.git
[Pipeline] echo
00:00:00.980  Repository: htpp://myrepo1.git
[Pipeline] echo
00:00:00.987  Branch: branch1
[Pipeline] checkout
00:00:00.998  using credential gittfscredentials
00:00:01.002   > git rev-parse --is-inside-work-tree # timeout=10
00:00:01.010  Fetching changes from the remote Git repository
00:00:01.010   > git config remote.origin.url htpp://myrepo1.git # timeout=10
00:00:01.018 Using shallow fetch with depth 1 00:00:01.018 Fetching upstream changes from htpp://myrepo1.git 00:00:01.018 > git --version # timeout=10 [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // ansiColor [Pipeline] } [Pipeline] // timestamps [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline an exception which occurred: in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals in object com.cloudbees.groovy.cps.impl.LoopBlockScopeEnv@469abe44 in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@71325a45 in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@4955b455 in field com.cloudbees.groovy.cps.impl.CallEnv.caller in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@451fb812 in field com.cloudbees.groovy.cps.Continuable.e in object org.jenkinsci.plugins.workflow.cps.SandboxContinuable@747dbee2 in field org.jenkinsci.plugins.workflow.cps.CpsThread.program in object org.jenkinsci.plugins.workflow.cps.CpsThread@4b1cbc4d in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.threads in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@4312dc7f in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@4312dc7f Caused: java.io.NotSerializableException: java.util.LinkedHashMap$Entry 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.HashMap.internalWriteEntries(HashMap.java:1793) at java.util.HashMap.writeObject(HashMap.java:1363) at sun.reflect.GeneratedMethodAccessor1288.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.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.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.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.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.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.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.concurrent.ConcurrentSkipListMap.writeObject(ConcurrentSkipListMap.java:1437) at sun.reflect.GeneratedMethodAccessor1304.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:521) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:445) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:317) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:281) 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:131) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59) 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

I don´t guess what could be bad.

Any help please?

Ramanathan Muthaiah

unread,
Feb 17, 2020, 10:44:19 PM2/17/20
to Jenkins Users

judaondo

unread,
Feb 18, 2020, 2:49:43 AM2/18/20
to Jenkins Users
Thanks Ram,

it fixed that issue, but now I get the following (the status is SUCCESS but it doesn´t do anything):

[Pipeline] { (Checkout)
[Pipeline] echo
00:00:00.799  /var/lib/jenkins/staticfiles/cip-environmens-local-cloud/
expected to call WorkflowScript.gitCheckoutMultipleRepositories but wound up catching com.mycom.Logger.info; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
[Pipeline] echo
00:00:00.852  INFO: Clonning 'htpp://myrepo1.git - (branch1 branch)' repository.
[Pipeline] }
[Pipeline// stage
[Pipeline] }
[Pipeline// ansiColor
[Pipeline] }
[Pipeline// timestamps
[Pipeline] }
[Pipeline// node
[PipelineEnd of Pipeline
Finished: SUCCESS

Reinhold Füreder

unread,
Feb 18, 2020, 4:05:21 AM2/18/20
to jenkins...@googlegroups.com

Hi „judaondo“,

 

  1. Ad “but it doesn’t do anything”: in @NonCPS annotated methods you must not call pipeline steps like “checkout” => seemingly this is skipped (?) rather silently
  2. However, in addition the warning log “expected to call WorkflowScript.gitCheckoutMultipleRepositories but wound up catching com.mycom.Logger.info; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/” also sounds very suspicious…
  3. I guess the iteration over “repositories” parameter is the original culprit: from Jenkins CPS/pipeline point of view using a non-serializable LinkedHashMap$Entry

 

HTH Reinhold

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fe386c57-b395-4830-b108-35855ec204be%40googlegroups.com.

judaondo

unread,
Feb 18, 2020, 4:50:01 AM2/18/20
to Jenkins Users
Thank you "r.fuereder".

I finally managed to solve it. What I did was to change the way of iteration using:

def map = [
           'iPhone':'iWebOS',
           'Android':'2.3.3',
           'Nokia':'Symbian',
           'Windows':'WM8'
           ]

map.each{ kv -> println "${k}:${v}" }
Here the whole code.

#!/usr/bin/env groovy

import com.mycom.Logger

/**
 * Clone the selected git repositories.
 *
 * Example usage within a declarative pipeline:
 *
 *    steps {
 *        gitCheckoutMultipleRepositories (["http://myrepo1.git": "branch1", "http://myrepo2.git": "branch2"])
 *    }
 *
 * @param repositories (Map) git url and branch of the git project to be downloaded.
 */
def call(Map repositories = ["http://myrepo1.git""branch1""http://myrepo2.git""branch2"]) {
    def logger = new Logger()
    repositories.each{ repositorybranch -> 
        def foldername = repository.tokenize('/')[-1].toLowerCase()
        logger.info("Clonning '${repository} - (${branch} branch)' repository.")
        println("Foldername: " + foldername)
        println("Repository: " + repository)
        println("Branch: " + branch)
        checkout([$class: 'GitSCM', branches: [[name: "${branch}"]], 
                    doGenerateSubmoduleConfigurations: false
                    extensions: [
                        [$class: 'CloneOption', depth: 1, noTags: false, reference: '', shallow: true], 
                        [$class: 'RelativeTargetDirectory', relativeTargetDir: "${foldername}"]
                    ], 
                    submoduleCfg: [], 
                    userRemoteConfigs: [[credentialsId: 'gittfscredentials'
                                    url: "${repository}"]]])
    }

}

To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages