Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To configure available Groovy installation on your system, go to Jenkins configuration page, find section 'Groovy' and fill the form as shown bellow.


If you doesndon't configure any Groovy installation and select (Default) option in a job, the plugin will fallback into calling just the groovy command, assuming you have groovy binary on the default path on given machine.

...

To create Groovy-based project, add new free-style project and select "Execute Groovy script" in the Build section, select previously configured Groovy installation and then type your command, or specify your script file name. In the second case path taken is relatively from the project workspace directory.

Jenkins 1.x:


Jenkins 2.x:

Jenkins 2.xImage Added

The plugin also adds the functionality of the Script Console to the project configuration page.

You can schedule your system management script...


Image RemovedImage Added

...and then observe progress in the build log.


Image RemovedImage Added

Groovy Script vs System Groovy Script

The plain "Groovy Script" is run in a forked JVM, on the slave where the build is run. It's the basically the same as running the "groovy" command and pass in the script.

The system groovy script, OTOH, Groovy script on the other hand runs inside the Jenkins master's JVM. Thus it will have access to all the internal objects of Jenkins, so you can use this to alter the state of Jenkins. It is similar to the Jenkins Script Console functionality.

...

System groovy jobs has access to whole Jenkins, therefore only users with admin rights can  add add system groovy Groovy build step and configure the system groovy Groovy script. Permissions are not checked when the build is triggered (i.e. also uses without admin rights can also run the script). The idea is to allow users run some well defined (defined by admin) system tasks when they need it (e.g. put slave offline/online, when user wants to start some debugging on slave). To have Jenkins instance secure, the support for Token macro plugin has to be switched off, see section bellowbelow.

Token macro plugin support

...

Code Block
System.getProperty('FOO')

Usage with pipeline

Currently the plugin does not support pipeline syntax. One workaround from Unknown User (alexander_samoylov) was mentioned here: https://stackoverflow.com/a/58381147/4807875.


Changelog

Release 2.2 (2019-03-06)
Release 2.1 (2019-01-28)
Release 2.0 (2017-04-10)
  • Arbitrary code execution by unprivileged user (SECURITY-292)
  • continue with code cleanup - fixed Findbugs issues

...