如何通过Jenkins作为一个独立进程来运行JAR文件?

huangapple go评论46阅读模式
英文:

How to run jar through jenkins as a separate process?

问题

问题是这样的:我需要在节点上运行一个jar文件,在Jenkins流水线中我写了以下代码

       stage('Start bot') {
                  steps {
                      sh 'nohup java -jar /home/oomnpe/workspace/oomnpe_bot/target/oomnpe_bot-1.0-jar-with-dependencies.jar'
                  }
                }

但是在启动jar文件后,构建进程无休止地进行下去,显示应用程序的日志,如果向它发送请求的话。如果我停止构建,应用程序也会停止。

如何使jar文件在远程机器上运行并停止构建?到处都写着关于“nohup”的内容,但我使用了它,结果没有。

英文:

The question is this: I need to run a jar file on the node, in the Jenkins pipeline I write

       stage('Start bot') {
                  steps {
                      sh  'nohup java -jar /home/oomnpe/workspace/oomnpe_bot/target/oomnpe_bot-1.0-jar-with-dependencies.jar'
                  }
                }

But the build goes on endlessly after launching the jar, showing the logs of the application, if you make requests to it. If I stop the build, then the application also stops.

How to make the jar run on the remote machine and the build stop? Everywhere they write about "nohup", but I use it and there is no result.

答案1

得分: 0

尝试以下内容。查看问题以获取更多详细信息。

withEnv(['JENKINS_NODE_COOKIE=dontkill']) {
    sh "nohup java -jar /home/oomnpe/workspace/oomnpe_bot/target/oomnpe_bot-1.0-jar-with-dependencies.jar &"
}
英文:

Try the following. Check this issue for more details.

withEnv(['JENKINS_NODE_COOKIE=dontkill']) {
    sh "nohup java -jar /home/oomnpe/workspace/oomnpe_bot/target/oomnpe_bot-1.0-jar-with-dependencies.jar &"
}

huangapple
  • 本文由 发表于 2023年2月16日 03:35:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464666.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定