1.安装jenkins
下载war包,扔到tomcat里面即可,如果不能访问看看防火墙是否添加了8080端口。
2.安装maven和sonar服务器,见之前文章
3. 需要一个maven项目,关于怎样建一个maven项目,见之前文章。
4.安装插件
进入系统管理---系统设置
搜索下面两个插件并安装,
Sonar Plugin:集成sonar服务器端用的。
Deploy Plugin:发布包到相应服务器上的 。
5.jenkins配置
设置jdk
设置sonar runner(sonar runner客户端),由于电脑上没装sonar runner,所以让jenkins自动安装 。如果电脑上装了客户端sonar runner,配置客户端路径即可。安装sonar runner的过程见博客其他文章。
sonar runner可能出现这样一个错误:
ERROR: Caused by: The current batch process and the configured remote server do
not share the same DB configuration.
解决办法见安装sonar runner的文章
设置maven
设置sonar
Server URL为sonar服务器地址
6.项目配置
新建项目
设置svn
设置
设置构建后动作,这里设置了两个sonar和deploy war/ear to container。sonar是分析代码用的,deploy war/ear to container是发布项目到指定tomcat用的。要注意的是这两个
插件必须先安装,不然看不到这些选项。
7.发布应用的配置
第一个一般来说是target/项目名.war
容器这里配置的是tomcat,要注意tomcat需要配置用户名和密码,在tomcat的/conf/tomcat-users.xml中配置,配置如下:
<tomcat-users> <!-- NOTE: By default, no user is included in the "manager-gui" role required to operate the "/manager/html" web application. If you wish to use this app, you must define such a user - the username and password are arbitrary. --> <!-- NOTE: The sample user and role entries below are wrapped in a comment and thus are ignored when reading this file. Do not forget to remove <!.. ..> that surrounds them. --> <role rolename="tomcat"/> <role rolename="role1"/> <role rolename="manager-jmx"/> <role rolename="manager-script"/> <role rolename="manager-gui"/> <role rolename="manager-status"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="role1" password="tomcat" roles="role1"/> <user username="admin" password="admin123" roles="tomcat,manager-gui,manager-s cript,manager-jmx,manager-status"/> </tomcat-users>