002 jenkins中maven项目采用deploy container部署至远程tomcat容器

前言:1、项目为标准maven项目,框架为spring boot,构建后打包成war;

2、项目使用gitlab进行源码管理;

3、项目构建采用Maven Integration plugin插件;

4、项目构建后,war包采用Deploy to container Plugin插件,部署至远程tomcat容器;

5、使用到了jdk1.8、maven工具;

 

操作过程如下:

1、创建job任务;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

2、描述随便填;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

3、配置git源码管理;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

4、不选择触发器;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

5、不选择构建环境;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

6、构建前不添加操作;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

7、配置编译源及条件;

btms/pom.xml

clean install -Dmaven.test.skip=true

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

8、只有build success,才进行下一步;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

9、增加构建后操作;

 

1) 选择deploy war/ear to a container

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

2) 配置war包路径;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

3)添加tomcat容器;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

10、点击保存。点击立即构建。

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

 

11、其他;

1)tomcat8.x账号创建;

a、修改manager的context.cml,配置manager远程可访问;

002 jenkins中maven项目采用deploy container部署至远程tomcat容器

b、在tomcat的conf/tomcat-users.xml,添加manager角色;

<role rolename="manager-gui"/> 

<role rolename="manager-script"/>

<user username="btTomcat" password="xxx" roles="manager-gui,manager-script"/>

2)deploy container的缺陷;

用deploy container这种方式,有的时候会造成内存溢出。处理的方式是在构建后,执行编写的脚本,该脚本的功能是完全停止掉tomcat容器,然后再重启tomcat容器。不过,既然都是要自己写脚本了,倒不如用publish over ssh插件,将构建产物scp到远程服务器,然后执行可控脚本,来重启服务。