Issue
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:
- 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?
- 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
? - 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:
- Cannot successfully deploy war file in tomcat using jenkins
- Re-deploying a "versioned" war file from Jenkins to Tomcat fails
- Auto-Deploy war file from jenkins without Tomcat's Manager
- Jenkins auto deploy tomcat 7
- Jenkins WAR deployment
Solution
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.
Answered By - B--rian
Answer Checked By - David Goodson (JavaFixing Volunteer)