在 Jenkins 上构建 Maven 后将 webapp 部署到 Tomcat
Deploy webapp to Tomcat after Maven build on Jenkins
我正在尝试在 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 文件。我已经为 angular 应用程序完成了 war 部署。
- 为您的 tomcat 服务器创建一个 manager-script 角色用户。
- 在 Jenkins 中安装 部署到容器 插件
- 转到 Jenkins 作业的配置和 select 选项 部署到容器 post build 选项动作。
- 使用 tomcat 用户名和密码输入所有详细信息并保存配置。
- 在构建过程后在 Jenkins 中享受自动 war 部署。
详情可参考以下link
我正在尝试在 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 文件。我已经为 angular 应用程序完成了 war 部署。
- 为您的 tomcat 服务器创建一个 manager-script 角色用户。
- 在 Jenkins 中安装 部署到容器 插件
- 转到 Jenkins 作业的配置和 select 选项 部署到容器 post build 选项动作。
- 使用 tomcat 用户名和密码输入所有详细信息并保存配置。
- 在构建过程后在 Jenkins 中享受自动 war 部署。
详情可参考以下link