Groovy plugin

This plugin adds the ability to directly execute Groovy code.

 Configuration

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


 Usage

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.


The plugin also adds the functionality of the Script Console to the project configuration page. You can schedule your system management script...


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


Changelog

Release 1.2:

  • Added possibility to specify properties and script parameters.
  • Added script source choice (file/command) for system groovy scripts.
  • Used .exe instead of .bat on Windows (as suggested by Scott Armit).
  • Added configuration option for classpath and initial variable bindings for
    system groovy scripts.

Known bugs

  • Configuring more builders at once actually doesn't absolutely work. If you need more groovy builders in your project, you have to configure them one by one and always save project configuration before you add new one.

Labels

  Edit Labels
  1. Apr 01

    scott armit says:

    Thanks for this plugin. I've found one issue however (Windows server); if the pa...

    Thanks for this plugin. I've found one issue however (Windows server); if the path to a groovy script passes args, then the full string is quoted. For example, in the "Groovy script file" field, you may have, "build.groovy one two" ('one' and 'two' being args).

    The call to groovy.bat will look like, C:\Groovy-1.5.4\bin\groovy.bat "c:\hudson\jobs\groovy\workspace\build.groovy one two"

    The result is an exception because groovy.bat processes everything in quotes as one long filename:
    Caught: java.io.FileNotFoundException: C:\hudson\jobs\groovy\workspace\build.groovy one two (C:\hudson\jobs\groovy\workspace\build.groovy one two

    There is a hacky workound, after your build script name, put double quotes. In my example, build.groovy" one two . This closes the first double-quote, and the last added one gets ignored.

    Thanks

  2. Apr 01

    David Vrzalik says:

    Yep, the file field isn't intended for script parameters. Next version should le...

    Yep, the file field isn't intended for script parameters. Next version should let you specify parameters without any hacks.

    1. Apr 02

      scott armit says:

      Ok, thank you for the information. One other thing I found if you're interested....

      Ok, thank you for the information. One other thing I found if you're interested. Apparently 'groovy.bat' does not handle return codes well. So if you System.exit(1) for instance out of your 'groovy' code, Hudson will still report SUCCESS. It's not Hudson's fault, but groovy.bat. Some notes on the groovy web site mention that using the native launcher fixes this (groovy.exe versus groovy.bat). I downloaded your src and changed ".bat" to ".exe" and built the 'hpi' and it works such that my return codes are not ignored.

      Regards and thanks again for this plugin!

      1. Apr 02

        David Vrzalik says:

        Thanks, I don't use Windows so I don't have much chance to catch these problems....

        Thanks, I don't use Windows so I don't have much chance to catch these problems. I updated the code to use groovy.exe.

        1. Apr 02

          scott armit says:

          Wow, thanks for the fast fix. I'm mostly a linux guy, but have to support some W...

          Wow, thanks for the fast fix. I'm mostly a linux guy, but have to support some Windows stuff. Speaking of, I tried out the plugin on linux, and tried my "hack" to pass parameters, but linux being stricter about quotes, the hack doesn't work. So I added a scriptArgs textbox under the scriptFile textbox and it works great. I tested giving the path to a groovy file with spaces in it on windows, and it quoted properly: e.g. <path-to-groovy.exe> "C:\Documents and Settings\user\build.groovy" -option1 -option2

          The code is a little hacky as it's my first attempt at the plugin code, but I can get it to you if you're interested. Thanks again.