简体   繁体   中英

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

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.xx C:\\MyScript.bat

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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