def veriableset(){ def a = "test1" def b = "test2" def c = "test3" } def echomethod(){ echo a } node{ stage('test'){ veriableset(); echomethod(); } } I want to call the variable I defined in the method in another method.
I get the following error.
[Pipeline] { [Pipeline] stage [Pipeline] { (test) [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline groovy.lang.MissingPropertyException: No such property: a for class: groovy.lang.Binding at groovy.lang.Binding.getVariable(Binding.java:63) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:270) at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:291) at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:295) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29) at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20) at WorkflowScript.echomethod(WorkflowScript:7) at WorkflowScript.run(WorkflowScript:12) at ___cps.transform___(Native Method) What method should I use? Can you help me?
defin front of variable declaration:def a = 'test1'-->a = 'test1'