使用Jenkins将War文件部署到Tomcat的推荐方法? [英] Recommended way to deploy a war-file to a Tomcat using Jenkins?
问题描述
我正在寻找一种黄金方式,如何使用Jenkins将 war 文件myPortal.war
自动(重新)部署到Tomcat服务器上,假设Tomcat在另一台装有Tomcat的计算机上运行-经理正在运行.在我目前的詹金斯工作中,相关的Powershell构建步骤如下:
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:
- 是否真的需要运行Tomcat-manager-GUI并将相应的凭证硬编码到Jenkins-job中?考虑到我无法通过网络安装服务器,没有比这更优雅的方法了吗?
- 在哪种情况下我可以在部署WAR文件之前取消部署,而不会冒着先前部署的其余部分在目录
myPortal
中徘徊的风险吗? - 另一个问题是,在没有Jenkins作业失败的情况下,脚本可能会失败(例如由于凭据错误).
- 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.
我知道Jenkins的Tomcat插件,但这(a)还要求Tomcat经理正在运行,并且(b)我无法使用Jenkins Choice参数重新部署( $ServerURL
和%ServerURL
均无效),这似乎是 Jenkins问题无法使用参数化的容器.
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:
- 无法使用jenkins在tomcat中成功部署war文件
- 重新部署版本" Jenkins到Tomcat的war文件失败
- 在没有Tomcat管理器的情况下从jenkins自动部署war文件
- Jenkins自动部署tomcat 7
- Jenkins WAR部署
- 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
推荐答案
仅作记录:我们当前使用的解决方法是让其他一些软件进行部署.原因不是上述的安全问题,而是我们的客户要求使用他们选择的专有软件打包服务XYZ. Jenkins现在要做的就是使用该软件打包服务的API上传WAR文件.
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.
这篇关于使用Jenkins将War文件部署到Tomcat的推荐方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!