0

I am looking for the golden way how to automatically (re)deploy a war-file myPortal.war onto a Tomcat server using Jenkins, assuming the Tomcat is running on another machine with a Tomcat-manager running. The relevant powershell build step within my current Jenkins job is the following:

$user = "foo"
$pass = "bar"
$secpass = ConvertTo-SecureString $pass -AsPlainText -Force
$ServerURL = $ENV:Server
$Path = $ENV:WORKSPACE
$credential = New-Object System.Management.Automation.PSCredential($user, $secpass)
Invoke-WebRequest -URI "$($ServerURL)/manager/text/undeploy?path=/myPortal" 
                  -Method GET -Credential $credential -UseBasicParsing
Invoke-WebRequest -InFile "$($Path)\myPortal.war" 
                  -URI "$($ServerURL)/manager/text/deploy?path=/myPortal&update=true" 
                  -Method PUT -Credential $credential 
                  -ContentType  'application/zip' -UseBasicParsing

Here, I used the undeploy-command as described by Tomcat Documentation. My problem in detail:

  1. Is it really necessary to have the Tomcat-manager-GUI running and the according credential hard-coded into the Jenkins-job? Isn't there a more elegant way than that given that I cannot network-mount my server?
  2. Under which conditions can I leave out the undeployment before deploying the WAR-file without running into the risk of having remains of the previous deployment lingering around in the directory myPortal?
  3. Another issue is that the script may fail (due to e.g. wrong credentials) without the Jenkins job failing.

I am aware of the Tomcat-plugin for Jenkins, but this (a) also requires the Tomcat-manager to be running and (b) I am failing to redeploy using a Jenkins Choice parameter (neither a $ServerURL nor a %ServerURL works) which seems to be Jenkins issue that it is not possible use a parameterized container.

Here are the most relevant related posts, however they did not answer my question:

B--rian
  • 5,578
  • 10
  • 38
  • 89
  • You said that you are aware of Tomcat Container Plugin Jenkins, this is the easy way, but tomcat server should be in running, this might be enough for it.. – Chandra Sekhar Y Aug 09 '17 at 11:13
  • Good point, thank you Chandra! **Open detail:** Does that plugin really guarantee that the previous deployment is fully wiped? Besides, the Jenkins plugin is not available for Tomcat 8, what do I do here? – B--rian Aug 09 '17 at 11:22
  • you can write curl script to do that so. – Chandra Sekhar Y Aug 09 '17 at 11:40
  • A curl-script would be (from an architectural point) just the same as my PowerShell script above, i.e. I still would have to hard-code password and username, a solution which is not favorable for me. – B--rian Aug 09 '17 at 11:42

2 Answers2

0

Just for the record: The work-around we are currently using is to let some other software do the deployment. The reason for this was not the above-mentioned security-concerns, but a requirement of our customer to use a proprietary software packaging service XYZ of their choice. All Jenkins does now is to upload the WAR-file using the API of that software packaging service.

B--rian
  • 5,578
  • 10
  • 38
  • 89
0

I appreciate this is an older post but I have got it working using Jenkins on a unix server and curl...