0

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 &
MyTwoCents
  • 7,284
  • 3
  • 24
  • 52
  • Have you checked this issue ? https://devops.stackexchange.com/questions/1473/running-a-background-process-in-pipeline-job Could be helpful. – RUARO Thibault Dec 31 '19 at 09:05
  • Tried. Same result. Build keeps running – MyTwoCents Dec 31 '19 at 09:16
  • Same questions with answer : https://stackoverflow.com/questions/28500066/how-to-deploy-springboot-maven-application-with-jenkins/28501714 http://jenkins-ci.361315.n4.nabble.com/Managing-a-Spring-Boot-self-executable-application-td4720491.html – Uttam Kasundara Jan 01 '20 at 08:23

1 Answers1

0

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&
MyTwoCents
  • 7,284
  • 3
  • 24
  • 52