1

I have a Jenkins project that builds an application and then, if successful, copies the application to our test-environment and restarts the Tomcat server. The Tomcat startup takes around 90 seconds. How can I automatically and / or programmatically check if the Tomcat startup was successful so I can trigger a deploy to our staging environment? We have a monitor URL I could monitor, but I have no clues on how to implement this in Jenkins.

pkhamre
  • 371
  • 1
  • 16

2 Answers2

1

Create an ant scriptlet, and put two things into a parallel task:

  • Starting Tomcat with exec task
  • a condition element with socket listener for the http port of tomcat inside a waitfor. You can define the timout property, and if it is defined after the waitfor, you can use fail to fail the build. To check the property you can simply create a subtarget with conditional running and after waitfor you can call it.

So something like this:

<target name="runCheckedTomcat">
    <parallel>
        <sequential>
            <echo>Tomcat starts</echo>
            <exec command="start.bat" dir="tomcatdir">
            </exec>
        </sequential>
        <sequential>
            <waitfor timeoutproperty="timeout" maxwait="15" maxwaitunit="second">
                <socket server="localhost" port="8080"/>
            </waitfor>
            <antcall target="fail"/>
        </sequential>
    </parallel>
</target>

<target name="fail" if="timeout">
    <fail message="Tomcat is not started in time"/>
</target>
Gábor Lipták
  • 9,646
  • 2
  • 59
  • 113
  • This will not work since Tomcat starts to listen on :8080 immediately after server start. I did notice that the shutdown port (8005) did not start before the application was up, so I might be able to use this. Not sure if it's a proper methods though. – pkhamre Oct 22 '12 at 08:22
  • You can use GET task instead (http://goo.gl/vvo6N). You can pick one page of your application, and you can even check its content. GET also has a timeout, so you can use it as a replacement or additional check to waitfor. The Ant-Contrib (http://goo.gl/pty4L) task collection contains IF task, which is really useful to have conditional parts in ANT. – Gábor Lipták Oct 22 '12 at 08:26
1

I simply solved this by setting up a simple exec-job in Jenkins that executes the following command.

curl -f -m 120 -o /dev/null -s -S http://example.org:8080/application
pkhamre
  • 371
  • 1
  • 16