How can I have Jenkins restart a Tomcat instance after a successful deployment?
I already tried using a batch script, but the Tomcat instance is killed when the build is finished.
Your answer lies in Jenkins ProcessTreeKiller. A more detailed explanation here.
It's a design decision to kill any processes that are spawned by the build to maintain a clean environment. Unfortunately that means you can't leave a process (such as Tomcat) running after the build.
You can disable this functionality globally (not recommended) by launching Jenkins like this:
java -Dhudson.util.ProcessTree.disable=true -jar jenkins.war
Or you can disable this on a per-case basis, by launching the process with a changed environment variable:
BUILD_ID=dontKillMe ./catalina restart
Some people report however that changing BUILD_ID
is not enough. They recommend also unsetting:
JENKINS_COOKIE
JENKINS_SERVER_COOKIE
Edit:
Another issue that could be at play is that when you connect to remote shell, and start a process in that remote shell session, once you (Jenkins) disconnects, the session is killed and all processes spawned by the session are killed too. To get around that issue, you need to disassociate the process from the shell session.
One way is:
nohup ./catalina restart &