Using psexec with Hudson, Ant and Groovy
Facts - Other software technologies
Saturday, 24 January 2009 10:02

With Hudson and Ant it is possible to compile and build complex systems from their sources. Most of my Ant targets contain Groovy script tasks. From these groovy tasks it is possible to invoke commands on remote servers using the Ant-exec task calling psexec, at least on a windows environment. The more general alternative would be using the sshexec Ant task, but in our case it was not possible to set up any ssh servers.

The first thing I found was that the flag "-accepteula" must be used when calling psexec from my Ant build script.

Another problem was that psexec sometimes hung after which our build needed to be restarted. This is especially a problem when a built needs to invoke psexec many times. Therefore I tried to combine multiple remote commands in a windows batch script and execute this batch script with psexec. This reduced the number of calls to psexec to just one and therefore it also minimized the chance that the build would fail.

Unfortunately psexec hung each time when executing a remote batch file from the Hudson Ant build script. I tried to invoke the same psexec command calling the same batch file from my emacs cygwin shell, with the same result. Then I tried to invoke the psexec from a dos command prompt which was successful. This problem could be related to terminal properties of the Hudson console output and the emacs cygwin shell.

Therefore the solution to this problem was redirecting the output of the batch script to a file on the remote server. Failures while executing the batch script could be detected by setting the attribute failonerror in the ant exec task calling psexec to "false". In the next step in the Ant build script the redirected output was copied to the workspace on the Hudson server. From there the Ant build script could read the file as a (groovy) string and analyze the output for errors.

Note January 2012: the Hudson built system was bought by Oracle. As a result Hudson is now maintained by new team of developers. The existing Hudson developers and most plugin developers started developing a new branch of Hudson called Jenkins.