jenkins简单持续集成更新

本文介绍了一种利用Maven和Jenkins实现Java Web应用程序自动化构建与部署的方法。主要内容包括配置Maven的pom.xml文件以进行资源管理及打包、使用特定插件如DeploytocontainerPlugin进行部署、通过Shell脚本实现Tomcat服务的更新重启等关键步骤。

1、所需插件名称

Deploy to container Plugin

Jenkins SSH plugin

2、pom profiles配置

<profiles>
<profile>
            <activation>
              <activeByDefault>true</activeByDefault>
           </activation>
        <id>develop</id>  
        <properties>
           <jdbc.username>root</jdbc.username>
         ……
    </properties>
……
</profile>
…… 
</profiles>
<!--包含的资源目录-->
<build>
  	<resources>
    	    <resource>
  	        <directory>src/main/resources</directory>
  	        <includes>
  		    <include>**/*.*</include>
  	        </includes>
  	        <filtering>true</filtering>
  		</resource>
  	    </resources>
  	<plugins>
  			<plugin>
	        <artifactId>maven-war-plugin</artifactId>
	        <version>2.6</version>
  			<configuration>
		   		<webResources>
		     		<resource>
		       			<filtering>true</filtering>
		       			<directory>src/main/webapp</directory>
		       			<includes>
		         			<include>**/*.xml</include>
		       			</includes>
		     		</resource>
		  		</webResources>
	 		</configuration>
	 	</plugin>
  	</plugins>
</build>

3、maven 打包参数 :clean  install  -P test

4、Deploy to container Plugin使用配置

182443_9IRu_233670.jpg

5、新建执行更新服务器的shell job 

#关闭指定端口号的tomcat
netstat -antp |awk '/:9080/{print $NF}'|awk -F'/' '{print $1}'|xargs kill -9 
#切换到tomcat目录
cd /home/appuser/apache-tomcat-x/
#删除tomcat日志logs文件夹里的全部文件
rm -fr logs/*
#删除tomcat jsp文件缓存
rm -rf work/Catalina/*
#删除上一次备份应用部署文件
rm -rf bak/*~
#删除上一次备份应用war文件
rm -rf war/*~
#将应用移到bak文件夹备份
mv -fb webapps/w/x bak
#将发布的应用war移到war目录下备份
mv -fb webapps/tomcat/x.war war
#将发布的应用移到指定的虚拟主机下
mv -fb webapps/tomcat/x webapps/w/
#启动tomcat
./bin/startup.sh


转载于:https://my.oschina.net/dyxp/blog/537532

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值