首页 > 解决方案 > Run a springboot jar with Jenkins Build command

问题描述

I am trying to automate a SpringBoot Application through Jenkins.

I have myApp.jar and currently, I run it using the following command

nohup java -jar myApp.jar & 

Press Ctrl^C or Ctrl^Z and process keep running in the background.

Logs will be added in nohup.out

Now I want the same process to be done using Jenkins.

In Jenkins, build section, I have selected Execute Shell Script with the above command.

When build is triggered. I can see Application startup Log in Jenkins Log but the problem is, build never finishes.

I have tried

BUILD_ID=dontKillMe timeout --foreground 30 nohup java -jar website-status.jar &

also

BUILD_ID=dontKillMe nohup java -jar website-status.jar &

timeout is killing the process. I don't want process to be killed.

Edit 1:

I have tried this as well. Build keeps running.

JENKINS_NODE_COOKIE=dontKillMe nohup java -jar website-status.jar &

标签: spring-bootjenkins

解决方案


When we execute command like this

nohup java -jar myApp.jar & 

a prompt is shown saying log will be written in nohup.out file and this was causing the script to hang forever in Jenkins.

I changed the command and now no prompt and works fine, logs are written in server.log

nohup java  -jar myApp.jar >> server.log 2>&1&

推荐阅读