The command it runs, âmvn spring-boot:runâ is a foreground task meant for development purposes as documented in Running Your Application :: Spring Boot, as it is using the Maven plugin for Spring Boot quick
Unless this task receives a âstopâ (Using Ctrl-C in a Terminal) or âkillâ signal (aborting the pipeline), it will keep running in foreground, hence the behavior of the pipeline.
What is the expected goal of the pipeline: is it to build and test the application? Or is it something else?
Hi @dduportal thanks for response. Right, expected goal was for development environment. I assume if i run java -jar cactus-0.0.1-SNAPSHOT.jar behavior will be the same ? (infinite loading)
Yes, it will be the same result: the application will be running in foreground.
Usual web servers are running in background and are managed by a secondary system (command systemcl for instance on Linux, or âRestart-Serviceâ on powershell).
You can send the application in background, but you have to be careful: if the pipeline stops, you need a system (usually named âGarbage collectingâ) to make sure the background application is stopped.
A Jenkins pipeline is not aimed at running an application. It is an automation engine, usually used for Continuous Integration (aka. âLintâ â âBuildâ and âTestâ) and Continuous Deployment (CI â âDeployâ).
Of course you might want to start and stop the application for running tests: in that case itâs not the pipelineâs role to start and stop the application. Itâs the development tool: in your case, it is Mavenâs role, as it has Spring boot plugin to help you. You should read Testing in Spring Boot | Baeldung for instance to learn.
The pipeline role would be to run the mvn test or mvn verify commands, which would take care of starting/stopping an instance of the application for each test suite.
Instead, if you want to deploy your application using a pipeline, then you have to explain to us what is the deployment target and the system used to start and stop the application. Usually, your pipeline will build the application artifact (e.g. the JAR file in your case) and then will deploy it to the target environment (e.g. copy it and restart the application server).
You mentioned starting and stopping the application, if the commands above are used to start it, I assume that a separate pipiline is needed to stop the application. Isnât that right?
You also mentioned the system (usually called âGarbage Collectorâ), can you please elaborate?
Use Jenkins to build and deploy the application but do not use Jenkins to run the application in the way you want to do it.
The pipeline here will block and waits for the application to finish.
And how do you know for your stop pipeline which process it needs to kill?
Usually on Linux but also Windows an application that should always run is installed as a service. This ensures that when the machine is rebooted (e.g. after installing OS patches) the application automatically starts.
Services also have features to automatically restart the application if it crashes.
Note that you might need proper permissions to start/stop services, e.g on Linux you usually must be root to do this.
For customer facing applications I consider starting it the way you want to do it as a no go.