dermoritz
dermoritz

Reputation: 13001

auto start stop remote tomcat before redeploying war by jenkins (deploy plugin)

at the moment jenkins build my project and at the end the artifact is deployed on a remote tomcat via jenkins deploy plugin. the problem is that after several redeployments this process fails (sometimes tomcat hangs or (un)deployment fails). in all cases stopping tomcat and manually undeploying helps.

Is there a way to stop tomcat before building/deploying, delete the old war and appfolder, and restart tomcat before deploy plugin wants to deploy the artifact?

thx in advance

Upvotes: 6

Views: 10043

Answers (2)

dermoritz
dermoritz

Reputation: 13001

one addition to accepted answer: it is important to reroute the output and error output of PsExec call (took me 2 days of debugging). See http://jenkins.361315.n4.nabble.com/remotely-executing-commands-td3476417.html

it seems that if called from java (like jenkins/tomcat) or .net PsExec hangs or quits with error. so the call should look like:

c:\someBatchWithPsExec.bat >>log.txt>&1

or explicitly on every call:

PsExec.exe -u [domain\remoteuser] -p [password] /accepteula \remoteMachine net [stop|start] Tomcat7 >>log.txt>&1

i guess if jenkins runs with domain\user u don't have to mention it in command?! (just tried it but it didn't work - the net commands fail)

Upvotes: 1

Arek
Arek

Reputation: 2021

You could write a batch file that does all the things mentioned:

  • stop tomcat
  • delete war files
  • start tomcat again

Then you can add a new pre/post build task in job configuration as execute batch and simply point it to run your batch file.

Added: You can use PsExec - http://technet.microsoft.com/en-us/sysinternals/bb897553 It allows you to run processes remotely. Put batch on remote machine and from local one using Jenkins run sth like this: PsExec.exe \xx.xx.x.x C:\MyScript.bat

Upvotes: 2

Related Questions