I have a simple bash script file, which is triggered from pipeline job ( via SSH ). The deploy.sh contains more or less something like this:

cd /apps && java -jar "-Dspring.profiles.active=prod " "-Dserver.port=$PORT " \

And some other logic which is not so important. The pipeline via SSH executes:

bash /deploy.sh ${APPLICATION_NAME}

How to start deploy.sh in order the java -jar to be executed and separated from the deploy.sh in order my pipeline (job) to finish and in the same time, the java app to continue working on the machine? I tried with

cd /apps && nohup java -jar "-Dspring.profiles.active=prod " "-Dserver.port=$PORT " \

But the job stuck...

It will be cool to track and the exit from the java -jar, but it is not so important right now :)

2 Answers 2


If you want to run in parallel cd /apps and java -jar you should use a single ampersand, not two: cd /apps & java -jar. However, the java -jar command will not work if it assumes it is run within the /apps directory.

More in general, command1 & command2 will run command1 and command2 independently, in parallel.

Note that your CI/CD tool (assuming you're talking about CI/CD pipelines) may support running tasks in parallel, so you could also try to solve this issue in the pipeline definition, if this makes sense in your case.

  • Thank you for the info, but my problem is that the CI/CD job is not terminating because of the java -jar which starts a web server.. I separete the cd /apps and java -jar to be different commands, but it is the same.. I want to start the java -jar, and to exit the deploy.sh script in order to finish the Ci/CD and in the same time java -jar to continue working on the server
    – ROZZ
    Nov 20, 2022 at 17:20
  • If that is the case, you could run nohup and find a way to exit. For example: nohup <something> &> /dev/null
    – A. Darwin
    Nov 20, 2022 at 17:28
  • I've tried ... still no success :( nohup java -jar "-Dspring.profiles.active=prod " "-Dserver.port=$PORT " \ "/apps/$DEPLOYING_VERSION" &> /dev/null
    – ROZZ
    Nov 20, 2022 at 17:36
  • Somehow ... eveyrhing works with: cd /apps; nohup java -jar "-Dspring.profiles.active=prod " "-Dserver.port=$PORT " \ "/apps/$DEPLOYING_VERSION" > /apps/spring.log 2>&1 &
    – ROZZ
    Nov 20, 2022 at 18:04
cd /apps;
nohup java -jar "-Dspring.profiles.active=prod " "-Dserver.port=$PORT " \
"/apps/$DEPLOYING_VERSION" > /apps/spring.log 2>&1 &

Makes the magic.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .