I have a groovy variable that i would like to pass to a shell block for further processing, but i keep getting the error pasted bellow:
stages {
stage('First Stage - echo out available variables'){
steps{
script {
def string_var = "im a groovy variable"
echo "${string_var}" // This will print "im a groovy variable" just fine
sh """
echo """ + string_var + """
""" // This will error
sh """
echo ${string_var}
""" // This will error
sh ''' echo '''+ string_var +''' '''
sh "echo ${string_var}" // This will error
}
}
}
}
My error:
an exception which occurred:
in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@1ecb37ba
in field com.cloudbees.groovy.cps.impl.CallEnv.caller
in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@32070c3b
in field com.cloudbees.groovy.cps.Continuable.e
in object org.jenkinsci.plugins.workflow.cps.SandboxContinuable@641113f0