Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees Jenkins Enterprise - Managed controller
Resolution
In the main Pipeline script, as well as scripts it loads, scripts in vars/*.groovy
and the implicit outer scope of scripts in src/**/*.groovy
, implicit global variables such as env
are bound by default, the steps
variable can be used to access Pipeline steps
, and functions not otherwise defined are passed along to steps.
steps variable
class C implements Serializable { def stuff(steps) { steps.node { steps.sh 'echo hello' } } } def c = new C() c.stuff(steps)
But inside an explicit type definitions, the implicit script scope is not available, so anything needed must be passed in somehow—steps in the above case, so you can also use the more general example described below where the whole Script is being passed in.
script variable
class C implements Serializable { def stuff(script) { script.node { script.echo "running in ${script.env.JENKINS_URL}" } } } def c = new C() c.stuff(this)