Question

I am trying to start Tomcat by using maven antrun plugin in a job in Jenkins. I know I can use cargo for the same but I can't use it. Reason being I want the Tomcat with the application running after the build is over.

Here's the scenario - I have Job 1 which checks out a project->Builds it->deploys that on Tomcat. Another job say Job 2 checks out another project->builds and deploys it on an ESB and then runs Integration tests using the Tomcat deployed on Job 1. I need to stop Tomcat once in Job 1 which I am achieving using cargo:stop in the clean phase - then I am planning to start it using maven antrun after compile phase. Then again use cargo to redeploy the new war after package phase. I need to do this so that Tomcat is refreshed for every test build and doesn't suffer from Permgen etc.

Anyways problem is my following script runs fine from my command prompt i.e. it starts Tomcat fine and opens up a command window for Startup.bat. But when I try the same in Jenkins it is not getting executed and funny enough it does not complain - simple doesn't start 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>

The is the log I see in jenkins

[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)

I have tried both executable="C:\Windows\System32\cmd.exe" as well as executable="cmd.exe" - Same issue i.e. when run from command prompt it works fine but in jenkins this isn't starting tomcat and neither errors out.

have checked Jenkins - System Configuration and user.name is NEW-LT7-0064$. Not sure if that helps in any way, but when I run from command prompt the user is my windows logged in user. Also I am running Jenkins as Windows Service with the Local System Account.

I tried the following as well as suggested in the link https://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build That didn't work either on a Windows 64 bit Windows 7 machine

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>
Was it helpful?

Solution

Are you sure that tomcat does not start at all? IIRC Jenkins does not support spawning of long living processes of builds (see here).

Regarding tomcat the second comment might be helpful: starting tomcat as service rather than with shell script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top