gpt4 book ai didi

maven - 在 Jenkins 上构建 Maven 后将 webapp 部署到 Tomcat

转载 作者:行者123 更新时间:2023-11-28 21:57:46 25 4
gpt4 key购买 nike

在 jenkins 上的 maven 构建完成后,我正在尝试将 webapp.war 复制到 tomcat 的 webapp 文件夹。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-webapp-to-tomcat</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="Deploying webapp to Tomcat.">
<copy todir="${tomcat.webapps.dir}" force="true">
<fileset dir="${project.build.directory}">
<include name="*.war" />
</fileset>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>

我将 jenkins 用户添加到 tomcat 组

$ id -Gn jenkins
jenkins tomcat

我的 webapps 文件夹权限看起来像

drwxrwxr-x 10 tomcat tomcat 4,0K Aug 13 17:24 webapps/

构建完成后,复制失败

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (copy-webapp-to-tomcat) on project: An Ant BuildException has occured:
Failed to copy /var/lib/jenkins/workspace/project/target/webapp.war to /opt/tomcat/webapps/webapp.war due to java.io.FileNotFoundException /opt/tomcat/webapps/webapp.war (Permission denied)
[ERROR] around Ant part ...<copy todir="/opt/tomcat/webapps" force="true">... @ 4:50 in /var/lib/jenkins/workspace/project/target/antrun/build-Deploying webapp to Tomcat..xml

当我为 webapps 文件夹的其他用户添加写入权限时

drwxrwxrwx 10 tomcat tomcat 4,0K Aug 13 17:24 webapps/

复制成功,得到一个文件

-rw-r--r--  1 jenkins jenkins  22M Aug 13 17:48 webapp.war

jenkins 用户是tomcat 组的成员并且该组对webapps 文件夹有写权限不就可以了吗?

谢谢,谢谢

最佳答案

请研究 war 部署插件,而不是使用复制方法。将来它还可以让您在远程服务器上部署 war 文件。我已经为角度应用程序进行了 war 部署。

  1. 为您的 tomcat 服务器创建一个ma​​nager-script 角色用户。
  2. 在 Jenkins 中安装部署到容器插件
  3. 转到 Jenkins 作业的配置并在构建后 操作中选择选项部署到容器选项。
  4. 使用 tomcat 用户名和密码输入所有详细信息并保存配置。
  5. 在构建过程后享受 Jenkins 中的自动 war 部署。

您可以引用以下链接了解更多详情

https://www.packtpub.com/mapt/book/application_development/9781783553471/4/ch04lvl1sec33/deploying-a-war-file-from-jenkins-to-tomcat

关于maven - 在 Jenkins 上构建 Maven 后将 webapp 部署到 Tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45662176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com