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{ k, v -> 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{ repository, branch ->
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}"]]])
}
}
El martes, 18 de febrero de 2020, 10:05:21 (UTC+1), r.fuereder escribió:
>
> 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 <http://com.mycom.Logger.info>; see:
> https://jenkins.io/redirect/pipeline-cps-method-mismatches/
> <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
> - See
>
> https://jenkins.io/blog/2017/02/01/pipeline-scalability-best-practice#appendix-serializable-vs.-non-serializable-types
> - => Use a different way to iterate
>
>
>
> HTH Reinhold
>
>
>
>
>
> *From:* [email protected] <javascript:> <
> [email protected] <javascript:>> *On Behalf Of *judaondo
> *Sent:* Dienstag, 18. Februar 2020 08:50
> *To:* Jenkins Users <[email protected] <javascript:>>
> *Subject:* Re: shared library - hashmap error
>
>
>
> 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
>
> [Pipeline] End of Pipeline
>
> Finished: SUCCESS
>
>
>
>
>
>
>
> El martes, 18 de febrero de 2020, 4:44:19 (UTC+1), Ramanathan Muthaiah
> escribió:
>
>
> On Monday, February 17, 2020 at 8:06:57 PM UTC+5:30, judaondo wrote:
>
> 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
> <javascript:>
>
> in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
>
> in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@71325a45
> <javascript:>
>
> in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
>
> in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@4955b455
> <javascript:>
>
> in field com.cloudbees.groovy.cps.impl.CallEnv.caller
>
> in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@451fb812
> <javascript:>
>
> in field com.cloudbees.groovy.cps.Continuable.e
>
> in object org.jenkinsci.plugins.workflow.cps.SandboxContinuable@747dbee2
> <javascript:>
>
> in field org.jenkinsci.plugins.workflow.cps.CpsThread.program
>
> in object org.jenkinsci.plugins.workflow.cps.CpsThread@4b1cbc4d
> <javascript:>
>
> in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.threads
>
> in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@4312dc7f
> <javascript:>
>
> in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@4312dc7f
> <javascript:>
>
> 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?
>
>
>
> In your library, annotate the function with *@NonCPS*, like this:
>
>
>
> @NonCPS
> def call() {
> . . .
> }
>
>
>
> Why to annotate? Checkout the explanation here:
>
>
>
>
> https://stackoverflow.com/questions/31654497/how-to-fix-notserializableexception-error-during-jenkins-workflow-build
>
>
>
>
> https://stackoverflow.com/questions/40159258/impossibility-to-iterate-over-a-map-using-groovy-within-jenkins-pipeline/40166064#40166064
>
>
>
> /Ram
>
> --
> 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 [email protected] <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/fe386c57-b395-4830-b108-35855ec204be%40googlegroups.com
>
> <https://groups.google.com/d/msgid/jenkinsci-users/fe386c57-b395-4830-b108-35855ec204be%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/8c810983-eae1-4c1b-8a39-aae99ca005c6%40googlegroups.com.