Ant Exec Spawn Jobs Broke Under Hudson?

A recent update of Hudson, a great continuous integration engine, has fixed one bug, only to introduce a new one. On February 19th, 2009, Hudson bug #2729 (an issue about Hudson not cleaning up run-away processes after the build is complete) was fixed by Hudson now killing off all processes created by the build task, including intentionally spawned daemons or tasks you wanted to keep alive.

If, like me, you use an Ant task to start your application server using an exec task with the spawn set to true at the end of a Hudson build, this means that when you upgrade Hudson, your application server will stop starting, but the rest of your build will continue to work as expected.

The issue is captured in Hudson bug #3105. The work around is to set the BUILD_ID environment variable to “dontKillMe” for the process you wish to not be killed. The Hudson bug mentions solving this through setting the BUILD_ID via a build parameter, however that requires that you enter or accept the default parameter each time you want to run the build. Instead I simply added the environment variable to my exec task, like this:

great find. I’ve a similar problem when I use shell script to start my tomcat server after building the application, as soon as the job is done my tomcat stopped (or was killed rather). After spending some time I finally concluded using ant exec task is the best way to go using spawn option and I’m glad I found your article before pulling my hair out…