Managing a Spring Boot self-executable application

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Managing a Spring Boot self-executable application

Enrique Medina Montenegro
Hi,

I'm working on a project where we are taking a "microservice" approach with a bunch of Spring Boot self-executable JAR files (instead of generating the WAR file and deploying it to a servlet container).

Focusing on one of the microservices (just to make it simple), I managed to properly configure it as a project in Jenkins using Git as the Source Code Management and then Gradle to build it --> gradle build

After Jenkins executes the "gradle build" command, I need to "execute" the just-generated JAR file in a separate process, so Jenkins can finish up the build and wait for the next one (whatever the trigger mechanism is). However, I've been playing around different configurations to execute the JAR file and I cannot find the one which fits perfectly my requirements (remember: after gradle finishes the build, execute the JAR file and end the Jenkins build process).

To put it step-by-step, this is what I'm trying to achieve:

1. Pull latest changes from Git repository.

2. Execute shell to kill (if existing from a previous build) the current JAR execution.

3. Run the gradle build task.

4. Execute shell to start up the self-executable/bootable JAR file.

5. Email notification.

This is what I have accomplished so far, but not sure whether it's the best approach or not, so asking the experts in this list:

1. OK.

2. I'm using this script:

ps axf | grep user-project-service | grep -v grep | awk '{print "kill -9 " $1}' | sh

3. OK.

4. The challenge here is that I don't know upfront what the name of the JAR would be, so I found this workaround:

find $WORKSPACE/user-project-service/build/libs/ -name "*.jar" -exec java -jar {} --spring.config.location=$WORKSPACE/user-project-service/config/application.yml --spring.profiles.active=production \;

However, although Jenkins runs this shell script properly, it uses the same thread where Jenkins runs the build, so eventually the build keeps running forever and "linked" to the execution of the JAR file.

I then tried to execute it in the background by appending '&' at the end of the script:

find $WORKSPACE/user-project-service/build/libs/ -name "*.jar" -exec java -jar {} --spring.config.location=$WORKSPACE/user-project-service/config/application.yml --spring.profiles.active=production \; &

But then Jenkins seems to not like it, because although it executes the shell script, the JAR application is not started up. I presume this is due to the fact that Jenkins finishes up the build process and the system automatically kills the '&' process, not sure, but it definitively doesn't work.

Therefore, I would like to understand how to achieve in Jenkins the scenario where I have to build a JAR file, then execute it (java -jar <generated_jar_file>) and end up the build, leaving the JAR application running as an independent process.

Moreover, this example shows only one JAR file, but as you can imagine, I would be generating a bunch of them, and I would like to execute them as JAR files once they are build, all in independent processes. Should I set up one Jenkins job per microservice? Or should I handle all them together in a single job? Please advice.

Thanks in advance for your help.

Regards,
Enrique Medina.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Managing a Spring Boot self-executable application

keshav2211
This post has NOT been accepted by the mailing list yet.
Hi,

There is a simple solution if your are deploying on the same machine where your Jenkins is running.

Jenkins' child processes are linked to BUILD_ID.
So we need to fake the build id before triggering java -jar .....

So when running the deployment(I believe you are running it through a post build task(shell script)).
just put BUILD_ID=do_not_kill_me in the task and then trigger java -jar  ....