How to store "complex" variable in environment?

Viewed 134

I have two stages and I want to share the info object with their properties to the second stage

    stage("Enter deploy information") 
    {
        options 
        {
            timeout(time: 3, unit: 'MINUTES') 
        }
        steps 
        {
            script 
            {
                env.info = askForDeployInformation()
            }
        }
    }

    stage('Get artifact')
    {
        steps
        {
            customCopyArtifacts(env.info.BranchName, env.info.BuildNumber)
        }
    }

But this fails with this error:

 org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found: field java.lang.String BranchName
11:56:44    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.unclassifiedField(SandboxInterceptor.java:425)
11:56:44    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:409)
11:56:44    at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:353)
11:56:44    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:357)
11:56:44    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
11:56:44    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
11:56:44    at WorkflowScript.run(WorkflowScript:24)
11:56:44    at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.delegateAndExecute(ModelInterpreter.groovy:137)

How to store "complex" variable in environment?

1 Answers

You can't store complex objects in the environment variables. This goes for all the operating systems I know of. Only strings can be stored there. You can assign numbers or booleans:

env.VAR_1 = 12
env.VAR_2 = true

But these will anyhow be converted to strings ("12" and "true" respectively).

Related