知了小站 - IT人的小站 - 踩坑记录 https://www.ydyno.com/tag/%E8%B8%A9%E5%9D%91%E8%AE%B0%E5%BD%95/ Jenkins 远程执行 java -jar 脚本不生效,不退出的坑 https://www.ydyno.com/archives/1393.html 2021-12-04T16:26:00+08:00 今天用 Jenkins 自动远程部署 eladmin 遇到了两个坑,这里分享下具体问题以及对应的解决办法。第一个问题问题复现是 jenkins 远程执行 java -jar 的时候报错:nohup: failed to run command 'java': No such file or directoryjava 程序也不能成功运行解决办法在执行脚本前先执行 source /etc/profile 刷新环境变量。source /etc/profile && nohup java -jar **.jar > nohup.out 2>&1 &参考:https://blog.csdn.net/u013189824/article/details/85338221第二个问题问题复现解决完第一个问题后,出现 jenkins 部署不会自动停止的问题,只能等 jenkins 超时退出。虽然远程服务器 java 进程成功启动了,但是 jenkins 都是不稳定的构建。ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after 120,000 ms] Build step 'Send build artifacts over SSH' changed build result to UNSTABLE Finished: UNSTABLE解决办法通过从网上整合资料,终于是找到了解决办法,解决办法可以参考我的配置source /etc/profile cd /home/eladmin BUILD_ID=DONTKILLME nohup bash /home/eladmin/start.sh点击高级,勾选 pty参考: https://blog.51cto.com/u_15316348/3217477 、 https://blog.csdn.net/sinat_29821865/article/details/119906879 再次构建,完美解决