I have a problem assigning to the env
variable in loop. I basically want to copy everything from user input form to env:
for (elem in userInput)
env["${elem.key}"] = "${elem.value}"
however this fails with:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod
org.codehaus.groovy.runtime.DefaultGroovyMethods putAt java.lang.Object java.lang.String java.lang.Object
at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectStaticMethod(StaticWhitelist.java:189)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onSetArray(SandboxInterceptor.java:474)
at org.kohsuke.groovy.sandbox.impl.Checker$11.call(Checker.java:438)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedSetArray(Checker.java:445)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.setArray(SandboxInvoker.java:49)
at com.cloudbees.groovy.cps.impl.ArrayAccessBlock.rawSet(ArrayAccessBlock.java:26)
at WorkflowScript.run(WorkflowScript:120)
at ___cps.transform___(Native Method)
...
Assigning this way works:
env.KEY1 = userInput['KEY1']
env.KEY2 = userInput['KEY2']
However I'd still prefer to update the env
in a loop to avoid duplication and possibility of typos, is there any way to do that/merge with the input data somehow?
(and yes, the pipeline is declarative, running in a sandbox and it should remain as such)