jenkins执行脚本不退出

ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after XXX ms
错误信息:

Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /shfb_30/.jenkins/workspace/apollo_test/pom.xml to com.shfb.mobile/mobile/1.0-SNAPSHOT/mobile-1.0-SNAPSHOT.pom
[JENKINS] Archiving /shfb_30/.jenkins/workspace/apollo_test/target/mobile-1.0-SNAPSHOT.jar to com.shfb.mobile/mobile/1.0-SNAPSHOT/mobile-1.0-SNAPSHOT.jar
channel stopped
SSH: Connecting from host [iZ25txgf5wsZ]
SSH: Connecting with configuration [45.26_jenkins_docker] ...
SSH: EXEC: STDOUT/STDERR from command [/shfb_50G/apollo/apollo.sh] ...
开始运运行脚本
SSH: Disconnecting configuration [45.26_jenkins_docker] ...
ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after 68,342 ms]
Build step 'Send build artifacts over SSH' changed build result to UNSTABLE
Finished: UNSTABLE

我在使用Jenkins进行远程部署时,构建后执行的脚本没有正常退出导致。
我的脚本没有写错,干的事情就是启动项目。
而导致它没有正常退出的原因是:
Since you are executing a script from a non-TTY environment; The Jenkins is not able to get the exit properly, out of your script.
意思是:因为你是从一个非tty环境执行脚本;Jenkins不能正常从你的脚本中退出。
解决办法:

外国网友解释:
Since you are executing a script from a non-TTY environment; The Jenkins is not able to get the exit properly, out of your script.
因为您正在执行一个非tty环境的脚本;jenkins不能正确地离开你的脚本。
What you want is to exit immediately, after script execution! Don't want to wait for the entire timeout to happen and then disconnect improperly!
您想要的是在脚本执行后立即退出!不要等待整个超时发生,然后错误地断开连接!
Solution: Make it Exec in PTY. (Please tick the check-box as shown in attached screenshot)
解决方案:在PTY中使用Exec

参考地址:http://stackoverflow.com/questions/11290540/jenkins-text-finder-unable-to-success-my-build/22011893#22011893
我最近(2016-10-25)在配置新项目时,发现,即使是勾选了Exec in pty,出现了项目不能启动的问题。
1
2
 

执行的结果是项目没有启动:

之后我又去查资料,依然是在那个外国网站的下面一个人回答中,找到了解决的方法!
可能的原因是因为,在执行openapi start 命令时,刚启动,pty(伪终端)就断开连接,
解决的办法就是,让脚步在后台运行,也就即使伪终端断开了,项目依然可以启动完成。
之后我执行的脚本改为
nohup sh ggf10service.sh
1
其实就是在前面加上nohup;
外国网友后面还加了sleep 1:nohup sh ggf10service.sh & sleep 1
我没有加也可以!
这里还需要注意的地方是,启动成功后,Jenkins控制台会打印这么一句话
nohup: ignoring input and appending output to `nohup.out'
1
也就是说,当我们使用nohup命令的的时候,日志会被打印到nohup.out文件中去。
如果我们不做任何处理,会随着每次的重新启动,nohup.out会越来越大。
所以我在我执行的脚本中添加了
Cat /dev/null > nohup.out
这样每次启动时,都会先清空掉这个文件。
公网构建mobile 和uservice 说明:
地址:101.201.31.68/jenkins
Mobile 项目名称:mobile-api
Uservice 项目名称:uservice
提交代码后,无需调整其他参数,直接构建即可。

猜你喜欢

转载自blog.51cto.com/11520242/2170632