Unable to run nohup command from jenkins as a background process

Utsav Gupta picture Utsav Gupta · May 20, 2016 · Viewed 15.2k times · Source

UPDATE: Based on below discussion I have edited my answer for more accurate description.

I am trying to run a nohup command from jenkins. The full command is

nohup java -jar /home/.../jar/server-process-0.35.jar prod >> /var/../server-process-prod.log 2>&1 &

This command does not work. I can see status as success in jenkins but no java process in linux. When I do 'ps -ef | grep java'

However when I remove the last '&' , that is I change it from run in forground instead of background

It starts working. I can see the java process started.

The original command works fine If I run it on linux console.

I need to run it from jenkins in the original form that is as a backgorund process. So that it is independant of jenkins.

Any clues why is this happening?

Answer

Joao Vitor Marques picture Joao Vitor Marques · May 28, 2019

In your jenkins shell script try:

  export BUILD_ID=dontKillMe
  nohup java -jar your_java_app.jar &

It worked for me!