为什么我的 Bamboo 构建被 Java 子进程阻止?

发布于 2024-08-21 19:18:07 字数 2475 浏览 3 评论 0原文

我正在开发一个遗留的 Java Enterprise 服务器项目,尝试设置夜间构建。我们使用 Java 5、Maven 2、JBoss 4.2 和 Atlassian Bamboo 2.1.5。我们的想法是,我们的一台开发服务器上有一个 Bamboo 代理,并且 Maven 构建配置为硬部署生成的 .ear 文件,然后重新启动服务器。 (我们不能使用软部署,因为我们的遗留应用程序使用的库会在取消部署期间导致异常......我们将在某个时候摆脱那个该死的库,但不是现在。)我正在使用 JBoss Maven 插件这。当我在自己的机器(笔记本电脑、Win XP Professional)上运行 Maven 构建时,它工作得很好:服务器停止并使用最新构建重新启动,然后构建完成。

然而,当我尝试在我们的服务器(Win 2003)上运行夜间构建时,启动 JBoss 服务器后构建过程停止。 Bamboo 代理在日志中显示:

Build MYPROJECT-NIGHTLY-44 completed.

然后它在那里等待,构建永远不会完成 - 除非我手动关闭 JBoss 服务器,此时 Bamboo 构建过程将恢复并运行其构建后活动,然后终止于

Finished building MYPROJECT-NIGHTLY-44.

显然该过程在 Win 2003 上启动 JBoss 服务器会以某种方式锁定父进程,而同一进程在 Win XP 上独立运行。 JBoss 插件的相关代码如下所示(为简洁而重新格式化):

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();
}

需要 dump() 方法来刷新进程的输出缓冲区 - 没有它,进程将无法运行,就像这样也记录在 API 文档 中。但是,这在 Win 2003 上仍然不起作用。这段代码是否缺少或不正确?这是竹子的问题吗?任何帮助表示赞赏。

更新:我在服务器上从命令行测试了 Maven 构建,它运行得很好。所以这显然是一个 Bamboo 问题。看起来 Bamboo 代理直接或间接地绑定了从其构建过程派生的所有子进程,并等到所有子进程都终止后再声明构建完成。这对于构建代理来说听起来有点合乎逻辑...但对我来说却带来了不幸的后果:-(

更新 2: 我也在 Bamboo 讨论板上发布了这个问题,得到了 Atlassian 支持人员的一些回复但还没有决定性的结果。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度℉ 2024-08-28 19:18:07

我的相关Bamboo 论坛上的讨论的结果是:这似乎是Bamboo 的一个功能,因此没有直接的解决方法。建议的解决方案是使用 构建后命令插件 在构建后部署应用程序过程已完成。

我还没有尝试过这个,因为我找到了一种替代解决方案,可以通过 Tanuki 将我们的服务器部署为 Windows 服务,使用 Exec Maven 插件

The outcome of my related discussion on the Bamboo forum is: this seems to be a feature of Bamboo, so there is no direct workaround. The suggested solution is to use the post build command plugin to deploy the application after the build process has finished.

I have not tried this, as I found an alternative solution to deploy our server as a Windows service via Tanuki, using the Exec Maven Plugin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文