I am working on a legacy Java Enterprise server project, trying to set up nightly builds. We are using Java 5, Maven 2, JBoss 4.2 and Atlassian Bamboo 2.1.5. The idea is that we have a Bamboo agent on one of our dev servers, and the Maven build is configured to hard deploy the resulting .ear file, then restart the server. (We can't use soft deploy because our legacy application uses a library which causes an exception during undeploy... we will get rid of that damn library at some point, but not just yet.) I am using the JBoss Maven plugin for this. It works nicely when I run a Maven build on my own machine (laptop, Win XP Professional): the server is stopped and restarted with the latest build, and the build finishes.
However, when I try to run the nightly build on our server (Win 2003), after starting the JBoss server the build process halts. The Bamboo agent displays in the log:
Build MYPROJECT-NIGHTLY-44 completed.
And then it waits there, the build never finishing - unless I shut down the JBoss server manually, at which point the Bamboo build process resumes and runs its post-build activities, then terminates with
Finished building MYPROJECT-NIGHTLY-44.
Apparently the process to start the JBoss server somehow locks the parent process on Win 2003, while the same process runs independently on Win XP. The relevant code of the JBoss plugin looks like this (reformatted for brevity):
protected void launch( String fName, String params )
throws MojoExecutionException {
try {
checkConfig();
String osName = System.getProperty( "os.name" );
Runtime runtime = Runtime.getRuntime();
Process p = null;
if ( osName.startsWith( "Windows" ) ) {
String command[] = { "cmd.exe", "/C", "cd " + jbossHome + "\\bin & " + fName + ".bat " + " " + params };
p = runtime.exec( command );
dump( p.getInputStream() );
dump( p.getErrorStream() );
} else {
String command[] = { "sh", "-c", "cd " + jbossHome + "/bin; ./" + fName + ".sh " + " " + params };
p = runtime.exec( command );
}
} catch ( Exception e ) {
throw new MojoExecutionException( "Mojo error occurred: " + e.getMessage(), e );
}
}
protected void dump( final InputStream input ) {
new Thread( new Runnable() {
public void run() {
try {
byte[] b = new byte[1000];
while ( ( input.read( b ) ) != -1 ) {
}
} catch ( IOException e ) {
e.printStackTrace();
}
}
} ).start();
}
The dump()
method is needed to flush the output buffers of the process - without it the process can't run, as is documented in the API docs too. However, this still doesn't work on Win 2003. Is there something missing or incorrect in this code? Is this a Bamboo issue? Any help is appreciated.
Update: I tested the Maven build from command line on the server and it works perfectly. So it is apparently a Bamboo issue. Looks like the Bamboo agent ties all subprocesses forked from its build process directly or indirectly, and waits until all of them terminates before declaring the build to be finished. Which sounds sort of logical for a build agent... just has unfortunate consequences for me :-(
Update 2: I posted the issue on the Bamboo discussion board too, got some responses from an Atlassian support guy but no decisive results yet.