Auto start stop remote tomcat before redeploying the jenkins war (deploy plugin)

jenkins is currently building my project and at the end the artifact is deployed to the remote tomcat via the jenkins deployment plugin. The problem is that after several repeated deployments, this process fails (sometimes tomcat or (un) hangs). In all cases, it helps to stop tomcat and manually deploy.

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

thanks in advance

+6
source share
2 answers

You can write a batch file that does all of the above:

  • stop tomcat
  • delete military files
  • run tomcat again

Then you can add a new task before / after assembly to the task configuration, how to execute the batch, and simply point it to start the batch file.

Added: You can use PsExec - http://technet.microsoft.com/en-us/sysinternals/bb897553 It allows you to remotely start processes. Place the package on the remote machine and from the local one using Jenkins, run sth as follows: PsExec.exe \ xx.xx.xx C: \ MyScript.bat

+2
source

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

it seems that if a call from java (e.g. jenkins / tomcat) or .net PsExec hangs or fails. so the call should look like this:

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

or explicitly with each call:

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

I think if jenkins works with the \ user u domain, no need to mention this in the command ?! (just tried, but it didn’t work - network commands do not work)

+1
source

Source: https://habr.com/ru/post/907560/


All Articles