Recommended way to deploy a war-file to a Tomcat u

2019-06-10 06:35发布

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:

1条回答
The star\"
2楼-- · 2019-06-10 07:31

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.

查看更多
登录 后发表回答