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

2024-01-26

在 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 文件。我已经为角度应用程序完成了战争部署。

  1. 创建一个管理器脚本tomcat 服务器的角色用户。
  2. Install 部署到容器詹金斯插件
  3. 转到 Jenkins 作业的配置并选择选项部署到容器选项中后期构建 action.
  4. 输入 tomcat 用户名和密码的所有详细信息并保存配置。
  5. 构建过程后,享受 Jenkins 中的自动战争部署。

您可以参考以下链接了解更多详情

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Jenkins 上构建 Maven 后将 webapp 部署到 Tomcat 的相关文章

随机推荐