Search code examples
maventomcatjenkinsspring-bootmicroservices

How to deploy SpringBoot Maven application with Jenkins ?


I have a Spring Boot application which runs on embedded Tomcat servlet container mvn spring-boot:run . And I don’t want to deploy the project as separate war to standalone Tomcat.

Whenever I push code to BitBucket/Github, a hook runs and triggers Jenkins job (runs on Amazon EC2) to deploy the application.

The Jenkins job has a post build action: mvn spring-boot:run, the problem is that the job hangs when post build action finished.

There should be another way to do this. Any help would be appreciated.


Solution

  • The problem is that Jenkins doesn't handle spawning child process from builds very well. Workaround suggested by @Steve in the comment (nohuping) didn't change the behaviour in my case, but a simple workaround was to schedule app's start by using the at unix command:

    > echo "mvn spring-boot:run" | at now + 1 minutes
    

    This way Jenkins successfully completes the job without timing out.


    If you end up running your application from a .jar file via java -jar app.jar be aware that Boot breaks if the .jar file is overwritten, you'll need to make sure the application is stopped before copying the artifact. If you're using ApplicationPidListener you can verify that the application is running (and stop it if it is) by adding execution of this command:

    > test -f application.pid && xargs kill < application.pid || echo 'App was not running, nothing to stop'