Assigning a step to a variable in Jenkins Pipeline -
i have following pipeline script:
node { def mystep = sh mystep "ls -la" }
i thought steps visible variables , assigned variables can used later (for example choosing different step depending on conditions).
however, fails with:
[pipeline] end of pipeline groovy.lang.missingpropertyexception: no such property: mystep class: groovy.lang.binding @ groovy.lang.binding.getvariable(binding.java:63) @ org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.sandboxinterceptor.ongetproperty(sandboxinterceptor.java:232) @ org.kohsuke.groovy.sandbox.impl.checker$6.call(checker.java:282) @ org.kohsuke.groovy.sandbox.impl.checker.checkedgetproperty(checker.java:286) @ com.cloudbees.groovy.cps.sandbox.sandboxinvoker.getproperty(sandboxinvoker.java:28) @ com.cloudbees.groovy.cps.impl.propertyaccessblock.rawget(propertyaccessblock.java:20) @ workflowscript.run(workflowscript:3) @ ___cps.transform___(native method)
how can put step in variable use later without hardcoding name?
you can write method in pipeline wraps behavior want. have access script variables.
node { mystep("ls -la") } def mystep(string script) { sh(script) }
Comments
Post a Comment