Evaluates a Groovy script and injects the results into the environment. This script s powered by the Script Security Plugin; both Approved Script and Groovy Sandbox modes are available. For the new scripts it is recommended to use the Sandbox mode.

Usage

The groovy script must return a Map<String,String> Java object. You can access parameters and other environment variables through variables in the Groovy script. In the scripts you can also use the following variables.

currentJob
Current hudson.model.Job instance.
currentBuid
Current hudson.model.Run instance.
currentListener
Current hudson.model.TaskListener instance, which can be used for logging purposes.
out
Another logging instance as java.io.PrintStream. It is recommended to use currentListener instead of this variable when possible.

All listed variables can be used in both script modes. In the Sandbox mode the access to particular fields and methods may require an additional approval.

Example

For example, the Groovy can compute environment variables from user input parameters. The script below injects the COMPUTE_VAR environment variable according the CASE parameter value.


          def stringValue="StRinG";
          if ("upper".equals(CASE)){
            def map = [COMPUTE_VAR: stringValue.toUpperCase()]
            return map
          } else if ("lower".equals(CASE)){
            def map = [COMPUTE_VAR: stringValue.toLowerCase()]
            return map
          } else {
            return null;
          }