在 Jenkins 上构建 Maven 后将 webapp 部署到 Tomcat [英] Deploy webapp to Tomcat after Maven build on Jenkins

查看:28
本文介绍了在 Jenkins 上构建 Maven 后将 webapp 部署到 Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i'm trying to copy the webapp.war to the tomcat's webapp folder after the maven build on the jenkins has finished.

<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 组

i added the jenkins user to the tomcat group

$ id -Gn jenkins
jenkins tomcat

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

and my webapps folder permissions look like

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 文件夹的其他用户添加写权限时

when i add the write permissions to the other users for the webapps folder

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

复制成功,我得到一个文件

the copying succeeds and i get a file

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

jenkins 用户是 tomcat 组的成员并且这个组有 webapps 文件夹的写权限应该不够吗?

shouldn't it be enough that the jenkins user is a member of the tomcat group and this group has the write permission for the webapps folder?

谢谢,kopi

推荐答案

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

Please research for war deployment plugin instead using copy method. It will let you deploy war file on remote servers also in future. I have done war deployment for angular application.

  1. 为您的 tomcat 服务器创建一个 ma​​nager-script 角色用户.
  2. 在 Jenkins 中安装部署到容器插件
  3. 转到 Jenkins 作业的配置,然后在 post build 操作中选择选项 Deploy to container 选项.
  4. 使用 tomcat 用户名和密码输入所有详细信息并保存配置.
  5. 在构建过程后享受 Jenkins 中的自动战争部署.
  1. Create a manager-script role user for your tomcat server.
  2. Install Deploy to container plugin in Jenkins
  3. Go to configuration of your Jenkins job and select option Deploy to container option in post build action.
  4. Enter all details with tomcat username and password and save configuration.
  5. Enjoy automatic war deployment in Jenkins after build process.

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

You can refer following link for more details

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

这篇关于在 Jenkins 上构建 Maven 后将 webapp 部署到 Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆