_Side Note:_ I do not have access to install plugins etc this is why I am using pipeline scripts etc extensive which might not be optimal. I am just a user of our school's build server. The following code part of my shared library.
*Situation:* I have a global function
{code:java} p4c.withSwarm(credentials,p4Port,client,mapping,Closure body) {code}
_Implementation:_ {code:java} def withSwarmUrl(credentials,client,mapping,Closure body){ withCredentials([usernamePassword(credentialsId: credentials, passwordVariable: 'p4USERPASS', usernameVariable: 'p4USER' )]) { def url = swarmUrl(credentials,client,mapping) body(url,env.p4User,env.p4USERPASS) } }
def withSwarm(credentials,p4Port,client,mapping,Closure body){ withSwarmUrl(env.P4USER,env.P4CLIENT,env.P4MAPPING) { url,user-> def p4Ticket = ticket(credentials,p4Port) body(user,p4Ticket,url) } }{code}
Which I am using like this in my Jenkinsfile in a step: {code:java} p4c.withSwarm(env.P4USER,env.P4HOST,env.P4CLIENT,env.P4MAPPING,{ user, ticket, swarmUrl -> swarm.setup(user,ticket,swarmUrl) def reviewObject = swarm.reviewInfo(reviewId) msg = swarmReviewToMessage(reviewObject) msg = discord.mentionUser(msg) }) {code} The mention function is implemented as follows:
{code:java} def mentionUser(message,filterFile="discord_filter.json"){ if(!fileExists(filterFile)){ error("Could not find ${filterFile}") return null; } def content = "" script { content = readFile file: filterFile } def jsonSlurper = new JsonSlurper() def filterObject = jsonSlurper.parseText(content) filterObject.discord_users.each{ key, value -> message = message.replace("${key}","<@${value}>") } return message } {code} Whenever I am using this setup I end up with the following exception: {code:java} an exception which occurred: in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@fcafd7 in field com.cloudbees.groovy.cps.impl.CallEnv.caller in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@13817e5 in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@220483 in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@f8c2f3 in field com.cloudbees.groovy.cps.impl.CallEnv.caller in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@60419e in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@aea904 in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@18f41ab in field com.cloudbees.groovy.cps.impl.CallEnv.caller in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@11b98b6 in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@162c856 in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@10964e8 in field com.cloudbees.groovy.cps.impl.CallEnv.caller in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@629de in field com.cloudbees.groovy.cps.Continuable.e in object org.jenkinsci.plugins.workflow.cps.SandboxContinuable@8b2349 in field org.jenkinsci.plugins.workflow.cps.CpsThread.program in object org.jenkinsci.plugins.workflow.cps.CpsThread@e15e69 in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.threads in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@142961d in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@142961d Caused: java.io.NotSerializableException: groovy.json.internal.LazyMap 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(Unknown Source) at java.util.HashMap.internalWriteEntries(Unknown Source) at java.util.HashMap.writeObject(Unknown Source) at sun.reflect.GeneratedMethodAccessor256.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) 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.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.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.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(Unknown Source) at java.util.concurrent.ConcurrentSkipListMap.writeObject(Unknown Source) at sun.reflect.GeneratedMethodAccessor300.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) 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:552) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:529) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:516) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:440) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67) at java.util.concurrent.FutureTask.run(Unknown Source) 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(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) {code} But if I have my setup as following:
{code:java} p4c.withSwarm(env.P4USER,env.P4HOST,env.P4CLIENT,env.P4MAPPING, { user, ticket, swarmUrl -> msg = discord.mentionGroup("Hallo #test_bot") swarm.setup(user,ticket,swarmUrl) def reviewObject = swarm.reviewInfo(reviewId) msg = swarmReviewToMessage(reviewObject) }) echo discord.mentionUser(msg) {code} I do not have any exception and it works.
I am not sure if this is just a problem I made or if this is actually a bug.
Through debugging (I have tested this around 128 times) I figured out that it boils down to {code:java} if(!fileExists(filterFile)){ error("Could not find ${filterFile}") } def content = "" content = readFile file: filterFile {code} If I uncomment those lines I can execute the build with the initial setup. When I add @NonCPS I do not get any output. Like my return statement is null |
|
|