Posted by kohsuke
on May 2, 2009 at 8:26 AM PDT
Hudson 1.302 has a new CLI program to Hudson, and one of the first commands is an interactive groovy shell so that you can look at and change live Hudson servers.
"You can do everything from GUI" has always been one of Hudson's strengths, and we also have the REST API, but at the same time, CLI is also very useful for improving automation around administration, builds, and so on. So starting Hudson 1.302, I added a CLI agent to Hudson. CLI can be downloaded from your Hudson from http://server/hudson/cli, which also shows you the basic usage.
Internally, the interesting implementation detail of this CLI is that CLI is "dumb" — it doesn't have any hard-coded knowlege of any command, and instead it downloads the necessary code on-demand from the master via the same remoting technology that Hudson uses between the master and slaves, which is rather transparent to the program running on it.
This enables a single CLI jar to morph into whatever command that plugins on the master has provided. And once the necessary code is obtained, the CLI command can choose what to execute locally in CLI agent and what to execute on the master, making the optimal use of network.
As one of the first commands, I implemented a Groovy shell , which can be started like this:
$ java -jar hudson-cli.jar -s http://yourserver/hudson groovysh
Groovy Shell (1.6.0, JVM: 1.6.0_02-fastdebug)
Type 'help' or '\h' for help.
The underlying remoting technology enabled us to write this command in a single Java class of 45 lines (including empty lines and comments), so you can see how easy it is to write a new command in Hudson.
Since this shell is connected to the live Hudson instance, you can introspect the state of the running Hudson instance, or even changes them on the fly.
groovy:000> import hudson.model.*;
===> [import hudson.model.*;]
For example, you can define a new builder class in Groovy, and add it to your project, all on a live system (not that it's recommended, but it's a very useful tool for inspecting problems and applying a temporary bandaid.) This is also very useful if you are writing plugins and try out Hudson's behaviors. The interactivity of Groovy shell allows you to quickly figure out what API has what effects, which you can in turn bake into your code.
All in all, I really like Groovy. And if you have ideas about the CLI commands you'd like to see, please let us know.