简体   繁体   English

使用Jenkins发送文件或通过SSH执行命令时,脚本未退出

[英]Script not exiting when using Jenkins Send Files or Execute Commands Over SSH

I'm pretty new to setting up jenkins so please bear with me. 我刚开始设置詹金斯(Jenkins),所以请多多包涵。 I'm trying to remote execute a shell script that stops and starts up my stand alone Jetty deployment after Jenkins has finished building and deploying the files to this server. 我正在尝试远程执行一个Shell脚本,该脚本将在Jenkins完成构建并将文件部署到此服务器之后停止并启动我的独立Jetty部署。

http://imgur.com/PXGHqtl (screenshot of the Post Build settings on Jenkins coz I'm not 10 rep yet...) http://imgur.com/PXGHqtl(Jenkins coz上的Post Build设置的屏幕截图,我还不是10位代表...)

So the problem I'm having is that once the build reaches this stage and the Send Files over SSH plugin begins to execute the jetty.sh start script, I get a timeout error because the sh script seemingly doesn't return any completion acknowledgement (ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after 120,003 ms]). 所以我遇到的问题是,一旦构建达到此阶段并且通过SSH插件发送文件开始执行jetty.sh启动脚本,我会收到超时错误,因为sh脚本似乎不返回任何完成确认(错误:发布时发生异常,异常消息[Exec超时或在120,003 ms之后被中断]。 This causes the build to fail despite the jetty service starting up correctly. 即使码头服务正确启动,这也会导致构建失败。

I have tried playing around with the Advanced settings by enabling the "Exec in pty" but this causes the started up jetty service to be shut down again as soon as this step completes. 我已经尝试通过启用“ Ext in pty”来尝试“高级”设置,但这会导致启动的码头服务在此步骤完成后立即再次关闭。

Does anyone have suggestions as to what else I could try? 有人对我可以尝试的方法有任何建议吗? Is my approach correct or completely wrong? 我的方法正确还是完全错误?

Why I am getting the timeout error 为什么我收到超时错误
There's a built in timeout in the advanced section of the Send Files over SSH plugin. “通过SSH发送文件”插件的高级部分有一个内置超时。 By default it is set to time out at 120 seconds on inactivity on the SSH connection. 默认情况下,它设置为在SSH连接不活动时超时120秒。 In this instance I am running the Send Files over SSH post task with "Exec in Pty" option disabled . 在这种情况下,我正在运行“通过SSH发送文件”发布任务,并且禁用了“执行Pty”选项。 When this option is checked, the plugin will connect to the deployment server over a virtual SSH Terminal session and afterwards, it doesn't exit the session by itself so it simply waits for the timeout. 选中此选项时,插件将通过虚拟SSH终端会话连接到部署服务器,此后,它不会自行退出会话,因此仅等待超时。

Why the jetty service starts up but shuts down immediately 为什么码头服务可以启动但立即关闭
With the "Exec in Pty" option enabled , a proper SSH Terminal session is used to connect to my deployment server. 启用 “在Pty中执行”选项后,将使用正确的SSH终端会话连接到我的部署服务器。 This ties any outputs and processes to the actual terminal session. 这会将所有输出和过程与实际的终端会话联系在一起。 When the Send Files over SSH plugin completes the jetty startup script execution, it exits by itself but in doing so, kills any process launched by the script. 当通过SSH发送文件插件完成码头启动脚本的执行时,它会自行退出,但这样做会杀死脚本启动的所有进程。

Solution
After much digging around i found a solution to launch my script using a command: 'nohup ./jetty.sh start > /dev/null 2>&1 &' in place of my usual ./jetty.sh start command. 深入研究之后,我找到了一种使用以下命令启动脚本的解决方案:'nohup ./jetty.sh start> / dev / null 2>&1&'代替我通常的./jetty.sh start命令。 There is a downside to this though. 不过,这有一个缺点。 The output is not redirected to the terminal session so I won't know if my jetty service started up properly. 输出未重定向到终端会话,因此我不知道码头服务是否正常启动。 But for now I'm satisfied with the solution so far since it's only going to deploy to my development environments. 但是到目前为止,到目前为止,我对该解决方案感到满意,因为它只能部署到我的开发环境中。

Sources 资料来源
Terminating SSH session executed by bash script 终止bash脚本执行的SSH会话
Jenkins Text-finder unable to success my Build Jenkins Text-finder无法成功完成我的构建
Jetty server stops running after closing terminal window 关闭终端窗口后,Jetty服务器停止运行

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

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