Jenkins and Tomcat

1,703 views
Skip to first unread message

Pedro Perez

unread,
Aug 6, 2012, 12:20:03 PM8/6/12
to jenkins...@googlegroups.com
Hello,

I'm new to Jenkins and so far I love it...but I have an issue integrating with Tomcat. I have Jenkins stopping and starting Tomcat via ant script. However I've found that Jenkins process-killer shuts down tomcat for me after it's finished. I've read https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller and have tried to disable it, however I run Jenkins through Tomcat, and I'm not sure how to disable the process killer when Jenkins is run as a simple web app on Tomcat 7. I tried to simply override the BUILD_ID variable like this:

$BUILD_ID=dontKillMe

to no avail. Even if that worked though, I'm wondering if there is a "cleaner" solution to starting and stopping Tomcat with Jenkins. When using ANT to start/stop it usually works, but not 100% every time. I've read about a tomcat plugin for Jenkins, but I think it doesn't stop/start Tomcat in the order I need it...basically my build script does a code checkout, compile, stop tomcat, replace war, start tomcat, run tests against newly deployed web app. 

Does anybody know the "correct" way to interact with Tomcat and Jenkins?

Thanks
Pedro

Jeff

unread,
Aug 6, 2012, 12:50:04 PM8/6/12
to jenkins...@googlegroups.com
I'm a relative n00b to Jenkins but if I were you, I wouldn't run your application on the same tomcat instance.  You are making your life harder.  Why not create another instance for deploying/testing the app?  You can run multiple versions and/or instances of tomcat on different ports, run one in a VM or on another system.

Regardless, tomcat can undeploy/redeploy an application without stopping.  There is an ant Task for tomcat to allow deploying applications via the management API that do not require stopping or starting tomcat or affecting jenkins....unless it blows up or consumes memory, in which case it will mess up all applications running in that instance and kill your build/test processes anyway...so again, I wouldn't do it that way.

Also if you were using Maven to build, there is a plugin that allows you to start a new tomcat instance for testing then shuts it down afterward.  I've not used it though.  There could be something similar for ANT.
--
I ♥ DropBox !! 

Pedro Perez

unread,
Aug 6, 2012, 1:04:20 PM8/6/12
to jenkins...@googlegroups.com
Thanks for your reply ... I actually am using different Tomcat deployments for Jenkins and my other app...my difficulty was in disabling the process killer from Jenkins when Jenkins is run through Tomcat (there are lots of instructions on how to disable the process killer when Jenkins is run as a java process without Tomcat). 

I should look into that ANT task for deploying a webapp without stopping/starting Tomcat...I don't know much about how to set that up however.

Thanks!
P

Jeff

unread,
Aug 6, 2012, 1:29:38 PM8/6/12
to jenkins...@googlegroups.com

In the <$TOMCAT_HOME>/lib folder there should be a JAR called catalina-ant.jar.  Make sure it is in your ANT classpath.  Import the ant tasks in your ant script:

<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/> 
<taskdef name="list" classname="org.apache.catalina.ant.ListTask"/> 
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask"/> 
<taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"/> 
<taskdef name="roles" classname="org.apache.catalina.ant.RolesTask"/> 
<taskdef name="start" classname="org.apache.catalina.ant.StartTask"/> 
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask"/> 
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>

Then call it:

<target name="deploy_dev" description="Deploy the WAR to Tomcat"> 
  <deploy 
      path="/${app.name}" 
      username="${tomcat.dev.username}" 
      war="file:${package.name}/${war.build.dir}/${app.name}.war" 
      password="${tomcat.dev.pwd}" 
      url="${tomcat.dev.url}"
  /> 
</target>

Chris Marks

unread,
Aug 6, 2012, 1:34:16 PM8/6/12
to jenkins...@googlegroups.com

You might also look at the deploy plugin. It creates a post-build step that can remotely deploy a war to multiple containers including Tomcat.

Topher

Jeff

unread,
Aug 6, 2012, 1:40:36 PM8/6/12
to jenkins...@googlegroups.com
I tried the Jenkins deploy plugin but it wouldn't work with Tomcat 7 for some reason.  Maybe I missed something, but for my Maven projects, just ended up using the maven-tomcat7-plugin in the POM.

Pedro Perez

unread,
Aug 6, 2012, 2:30:12 PM8/6/12
to jenkins...@googlegroups.com
I tried both suggestions, the deploy plugin works great for me, as well as using an ANT script to deploy it...the only problem is I need to shut Tomcat down completely, manually place the .war, and then start up Tomcat--otherwise Tomcat will remove some DB configuration files i keep in /conf/Catalina/localhost. I wish there was a good way to stop/start/deploy applications from Jenkins (the deploy plugin is nice, but it only deploys...no controls to start and stop). 

I'd be happy if Jenkins would stop automatically killing the Tomcat process I start during the build, but I'm not sure how to disable the auto-kill feature of jenkins when running Jenkins through the Tomcat container...does anybody know how to do this?

P

Pedro Perez

unread,
Aug 6, 2012, 2:44:28 PM8/6/12
to jenkins...@googlegroups.com
Ok I figured it out. After it's finished building, Jenkins will destroy every process started during that build process. That is a bummer for those people like me that want to start Tomcat as part of the build process. If you're running Jenkins through Tomcat 7, you can disable it's auto kill functionality by adding this line to catalina.sh:

BUILD_ID=dontkillme

That will override the PID Jenkins keeps track of when it starts Tomcat, and thus Jenkins won't kill it. Hats off to you guys for your suggestions. 

Thanks for all your help!

Pedro
Reply all
Reply to author
Forward
0 new messages