Return value from Groovy script is treated as Label Expression. It is treated as followings:


Following variables are bound:

currentJob
The job to be built. For multi-configuration projects, an instance of MatrixProject is passed for a parent build and an instance of MatrixConfiguration is passed for a child build.

Additionally, following variables are bound, but there may be cases that some type of parameters are not set, or set to wrong value. This is for a build is not started yet when this Groovy script is evaluated.


Here is an example:

Example1----------------------------------------------------------------------------- // parameters defined in "This build is parameterized" are bound, // and you can use them just as variables. if(is_test == "true") { // use nodes labeled "debug_node" return "debug_node"; } // returning blank value does not restrict nodes. // When restricted with other parameters or plugins, that configuration will be used. return null; Example2----------------------------------------------------------------------------- // Values defined with axes with a multi-configuration project are also bound. // But that value is not defined in a parent build, // so access with binding.getVariables().get(VARNAME) . // (accessing VARNAME directly results exceptions) switch(binding.getVariables().get("target")) { case "Win32": case "Win64": // run on Windows. return "Windows"; case "Linux32": case "Linux64": // run on Linux. return "Linux"; } Example3----------------------------------------------------------------------------- // Decides the node to run on for its job name. ["win", "linux"].find(currentJob.name.contains(it))