0

I'm noob in linux! I have my server and installed jenkins. I need to create bash script, which should run application(or will restart if it has already been started) after jenkins compile it. I tried to use screen util in linux, but it's not working for me. I wrote this script:

screen -X -S JavaTelegramBot quit
screen -d -m -S JavaTelegramBot
screen -X -S JavaTelegramBot java -jar "path/to/jar" 

When I tip screen -ls , it's empty, so application not working. I even tried to use nohup. It's only launch application for few seconds, until jenkins finished his build. Scripts starting by using cmd command in jenkins after build

3
  • I'm not sure to understanf what you want to do. To start java application like jar file use > java -jar <application.jar> If you use a war file maybe you need server application like Tomcat or Jetty. If you created a spring boot web application you can create a systemd configuration file to run it like a daemon. Could you explain what kind of application did you create and how did you want to deploy it?
    – yohann
    Commented Aug 28, 2021 at 20:04
  • I created simply Bot, whithout spring. It's works if I run it manually. I want the application to run continuously. Deploy it on the same server where Jenkins is installed. My goal is to automate the update of this Bot. that is, if I make a Push in Github, the bot should immediately update and apply all updates. My only problem is that I can't automate its restart
    – Alex F
    Commented Aug 28, 2021 at 20:26
  • When asked for clarifications, please don't respond in comments, but edit your post to include the requested information. Reading through the comments is rather painful, and comments are subject to removal without notice by moderators.
    – AdminBee
    Commented Sep 6, 2021 at 13:09

1 Answer 1

0

This is due to Jenkins' Process Tree Killer, which kills any processes started by the Jenkins job after the job exits (even if you run the job in the background with screen/tmux/nohup/etc.).

According to the docs linked above, the way to prevent Jenkins from killing your long-running processes is to set an environment variable:

If your build wants to leave a daemon running behind...

A convenient way to achieve that is to change the environment variable BUILD_ID which Jenkins's ProcessTreeKiller is looking for. This will cause Jenkins to assume that your daemon is not spawned by the Jenkins build. For example:

BUILD_ID=dontKillMe /usr/apache/bin/httpd

In case of Jenkins Pipeline use JENKINS_NODE_COOKIE instead of BUILD_ID

1
  • Thanks for your answer! Gonna try it
    – Alex F
    Commented Sep 3, 2021 at 19:21

You must log in to answer this question.

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