【问题标题】:Recommended way to deploy a war-file to a Tomcat using Jenkins?使用 Jenkins 将战争文件部署到 Tomcat 的推荐方法?
【发布时间】:2018-01-16 06:55:29
【问题描述】:

我正在寻找如何使用 Jenkins 自动(重新)部署 war-file myPortal.war 到 Tomcat 服务器上的黄金方法,假设 Tomcat 正在另一台带有 Tomcat 的机器上运行-经理运行。我当前的 Jenkins 工作中相关的 powershell 构建步骤如下:

$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

在这里,我使用了Tomcat Documentation 中描述的undeploy-命令。 我的问题详解:

  1. 真的有必要让 Tomcat-manager-GUI 运行并将相应的凭据硬编码到 Jenkins 作业中吗?鉴于我无法通过网络安装我的服务器,难道没有比这更优雅的方法了吗?
  2. 在哪些情况下我可以在部署 WAR 文件之前忽略取消部署,而不会遇到先前部署的剩余部分在目录 myPortal 中徘徊的风险?
  3. 另一个问题是脚本可能会失败(例如由于凭据错误)而 Jenkins 作业不会失败。

我知道 Jenkins 的 Tomcat 插件,但这 (a) 还需要 Tomcat 管理器正在运行,并且 (b) 我无法使用 Jenkins Choice 参数 重新部署( $ServerURL%ServerURL 都不起作用)这似乎是 Jenkins issue 不可能使用参数化容器。

以下是最相关的帖子,但他们没有回答我的问题:

【问题讨论】:

  • 你说你知道Tomcat Container Plugin Jenkins,这是最简单的方法,但是tomcat服务器应该正在运行,这可能就足够了..
  • 好点,谢谢钱德拉! 打开细节: 那个插件真的保证之前的部署被完全擦除了吗?另外,Tomcat 8没有Jenkins插件,这里怎么办?
  • 你可以编写 curl 脚本来做到这一点。
  • curl 脚本(从架构角度)与我上面的 PowerShell 脚本相同,即我仍然必须对密码和用户名进行硬编码,这对我不利的解决方案.

标签: powershell tomcat jenkins deployment war


【解决方案1】:

我很欣赏这是一篇较旧的帖子,但我已经在 unix 服务器上使用 Jenkins 和 curl...

【讨论】:

  • 请扩展您的答案,使其对他人更有帮助
【解决方案2】:

仅作记录:我们目前使用的解决方法是让其他软件进行部署。其原因不是上述安全问题,而是我们的客户要求使用他们选择的专有软件打包服务 XYZ。 Jenkins 现在所做的就是使用该软件包服务的 API 上传 WAR 文件。

【讨论】:

    猜你喜欢
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 2012-11-27
    相关资源
    最近更新 更多