0

I'm pretty new to setting up jenkins so please bear with me. 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.

https://i.stack.imgur.com/dxVak.jpg (screenshot of the Post Build settings on Jenkins coz I'm not 10 rep yet...)

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]). 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.

Does anyone have suggestions as to what else I could try? Is my approach correct or completely wrong?

blaytenshi
  • 312
  • 3
  • 11
  • If you just need to execute a command in a remote machine over ssh, you can add another build step after you finish building and deploying with a command like `ssh user@remote.machine.com `. You need to make sure `user` is able to ssh to that machine passwordless, so the ssh key of that user should be copied into the remote machine where Jetty is running. – davidrv87 May 21 '15 at 15:05
  • Hiya david! Thanks for your comments! I had a check of the passwords and ssh permissions and they're all correct. I've found a solution my problems however so I'll update with an answer. – blaytenshi May 25 '15 at 03:35
  • No problem! What was the issue then? – davidrv87 May 26 '15 at 20:14

1 Answers1

4

Why I am getting the timeout error
There's a built in timeout in the advanced section of the Send Files over SSH plugin. By default it is set to time out at 120 seconds on inactivity on the SSH connection. In this instance I am running the Send Files over SSH post task with "Exec in Pty" option disabled. 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.

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. 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.

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. 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
Jenkins Text-finder unable to success my Build
Jetty server stops running after closing terminal window

Community
  • 1
  • 1
blaytenshi
  • 312
  • 3
  • 11