0

我正在尝试通过在 Jenkins 的工作中使用 maven antrun 插件来启动 Tomcat。我知道我可以使用货物,但我不能使用它。原因是我希望 Tomcat 在构建结束后运行应用程序。

这是场景 - 我有工作 1,它签出一个项目->构建它->在 Tomcat 上部署它。另一项工作说 Job 2 检查另一个项目->构建并将其部署在 ESB 上,然后使用部署在 Job 1 上的 Tomcat 运行集成测试。我需要在 Job 1 中停止一次 Tomcat,我使用 cargo:stop 在清洁阶段 - 然后我计划在编译阶段之后使用 maven antrun 启动它。然后在打包阶段后再次使用 cargo 重新部署新的战争。我需要这样做,以便每次测试构建都会刷新 Tomcat,并且不会受到 Permgen 等的影响。

无论如何,问题是我的以下脚本在我的命令提示符下运行良好,即它可以正常启动 Tomcat 并为 Startup.bat 打开一个命令窗口。但是当我在 Jenkins 中尝试相同的操作时,它并没有被执行并且足够有趣,它不会抱怨 - 简单不会启动 tomcat。

<plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <id>startTomcat</id>
                                <phase>compile</phase>
                                <configuration>

                                    <target>

                                        <exec executable="C:\Windows\System32\cmd.exe" spawn="true">
                                            <arg value="/c" />
                                            <arg value="D:\apache-tomcat-6.0.36\bin\startup.bat" />
                                        </exec>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

这是我在詹金斯看到的日志

[INFO] Executing tasks
Build sequence for target(s) `main' is [main]
Complete build sequence is [main, ]

main:
     [exec] Current OS is Windows 7
     [exec] Executing 'C:\Windows\System32\cmd.exe' with arguments:
     [exec] '/c'
     [exec] 'D:\apache-tomcat-6.0.36\bin\startup.bat'
     [exec] 
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.
Execute:Java13CommandLauncher: Executing 'C:\Windows\System32\cmd.exe' with arguments:
'/c'
'D:\apache-tomcat-6.0.36\bin\startup.bat'

The ' characters around the executable and arguments are
not part of the command.
spawned process java.lang.ProcessImpl@ed11c1
[INFO] Executed tasks
mojoSucceeded org.apache.maven.plugins:maven-antrun-plugin:1.7(startTomcat)

我已经尝试了 executable="C:\Windows\System32\cmd.exe" 以及 executable="cmd.exe" - 同样的问题,即当从命令提示符运行时它工作正常,但在詹金斯这不是启动 tomcat 和既不出错。

已检查 Jenkins - 系统配置和 user.name 是 NEW-LT7-0064$。不确定这是否有任何帮助,但是当我从命令提示符运行时,用户是我的 Windows 登录用户。此外,我使用本地系统帐户将 Jenkins 作为 Windows 服务运行。

我尝试了以下以及链接中的建议https://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build 这在 Windows 64 位 Windows 7 机器上也不起作用

Another workaraund for Windows XP and later is to shedule permanent task and force running it from the ant script.
Once run the command:

C:\>SCHTASKS /Create /RU SYSTEM /SC ONSTART /TN Tomcat /TR "C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\startup.bat"
Note, that ONSTART can be replaced with ONCE if you do not want to keep Tomcat running.
Add the following code to your ant script:

<exec executable="SCHTASKS">
    <arg value="/Run"/>
    <arg value="/TN"/>
    <arg value="Tomcat"/>
</exec>
4

1 回答 1

0

你确定tomcat根本没有启动吗?IIRC Jenkins 不支持生成长期存在的构建过程(请参见此处)。

关于 tomcat,第二条评论可能会有所帮助:将 tomcat 作为服务而不是 shell 脚本启动。

于 2012-12-14T16:05:57.650 回答