简体   繁体   English

运行bash脚本执行Java代码时,日志输出显示在Jenkins中

[英]Log output shows in Jenkins while running bash script to execute Java code

At first let me describe my issue. 首先,让我描述一下我的问题。 I configured Jenkins and after build action I called shell script to run bash script on remote server. 我配置了Jenkins,并在构建操作后调用了shell脚本以在远程服务器上运行bash脚本。 The shell script starts application via command Shell脚本通过命令启动应用程序

java -Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=xxx 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-XX:+HeapDumpOnOutOfMemoryError -jar name.jar "BUILD_PARAMETER"

I see logs from my application in Jenkins build, and it's keep build process running. 我在Jenkins构建中看到来自我的应用程序的日志,它使构建过程保持运行状态。 I need to finish it after running sh run command. 我需要在运行sh run命令后完成它。 Is it possible? 可能吗?

If you're doing this using Jenkins you will need to use the nohup notation as in the comments as well as specifying a non-numerial PID for the process. 如果您使用Jenkins进行此操作,则将需要使用注释中的nohup表示法,并为该过程指定非数字PID。 Jenkins tries to clean up after a job finishes by killing any processes it starts. 詹金斯(Jenkins)试图通过杀死作业开始的所有进程来清理作业。

BUILD_ID=dontKillMe nohup <-your command -> & BUILD_ID = dontKillMe nohup <-您的命令->&

the above command should work 上面的命令应该起作用

https://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build https://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build

Your shell script need to fork a process, and return, otherwise Jenkins thinks your shell script is still running (which it is, if it's not forking the process and returning). 您的Shell脚本需要派生一个进程,然后返回,否则Jenkins认为您的Shell脚本仍在运行(如果未派生该进程并返回,则它正在运行)。

You have not provided the command you use to launch your application, but a common way to fork a process in linux is: 您尚未提供用于启动应用程序的命令,但是在Linux中派生一个进程的常用方法是:

nohup <your command here> &

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM