Cristian M
Cristian M

Reputation: 357

Jar stops after Jenkins stage has finished

I have a Jenkins 2.401.1 server running. Inside it I am trying to create a declarative pipeline that should start a jar file. The pipeline builds the code in one Jenkins agent and by using 'stash', after the build is finished, the jar is copied to another agent. After this, the pipeline, tries to start the jar file with:

./startJar.sh

This sh file has the next content:

#!/bin/bash

nohup java -jar build/libs/leJar.jar > log/leJar.log 2>&1 &

exit 0

After the pipeline runs the step that executes'./startJar.sh' step, the jar appears to not start.

ps -ef

can tell this.

If I put a sleep after the step that starts the jar, the jar seems to be up and running and it stops when the pipeline stage is done. No error is thrown anywhere. Not even in 'journalctl'

Can someone please help?

Upvotes: 0

Views: 114

Answers (1)

Ruslan
Ruslan

Reputation: 605

try to use disown

java -jar build/libs/leJar.jar > log/leJar.log 2>&1 & disown

jenkins by logic creates sh script on agent/master then it will execute that script file and at the end will terminate shell process

Upvotes: 1

Related Questions