1.jenkins部署【linux环境】
下载最新的jenkins-1.651.1-1.1.noarch.rpm,并安装
rpm -iv jenkins-1.651.1-1.1.noarch.rpm
启动jenkins
service jenkins start
2.下载apache-maven-3.3.9-bin.tar.gz、ant 并解压
3.通过浏览器登录并配置
浏览器登录,默认访问端口是8080
系统管理-》系统设置
(1)设置JDK路径
(2)设置Ant
(3)设置Maven路径
4.添加插件
系统管理-》管理插件-》可选插件
安装插件及相关的依赖插件:
FindBugs Plug-in
Checkstyle Plug-in
PMD Plug-in
Static Analysis Collector Plug-in
Dashboard View
Matrix Project Plugin
##安装插件过程中可以需要翻墙,可以通过系统管理-》管理插件-》高级,配置代理
5.创建项目
新建,选择“构建一个自由风格的软件项目”
配置Subversion,项目url地址、用户名、密码
配置构建触发器,选择Poll SCM,设置定时器:@hourly(可随意指定)
构建,选择Maven版本,Goals提前设置为:“compile findbugs:findbugs checkstyle:checkstyle pmd:pmd”
构建后,增加Checkstyle results 、FindBugs results、PMD results,配置结果路径:**/checkstyle-result.xml、**/findbugsXml.xml、**/pmd.xml
最后增加Publish combined analysis results,选择Checkstyle warnings、FindBugs warnings、PMD warnings
存档构建后生成的文件:
Archive the artifacts,配置文件匹配规则
jenkins web页面配置结束
##如果要自定义workspace,在高级项目选项中配置
6.pom.xml配置
如果项目本身是用maven配置的,那配置起来很容易,但如果是用ant做build工作,可以使用maven调用ant进行build
点击(此处)折叠或打开
-
<plugin>
-
<artifactId>maven-antrun-plugin</artifactId>
-
<version>1.7</version>
-
<executions>
-
<execution>
-
<phase>generate-sources</phase>
-
<configuration>
-
<tasks>
-
<property name="compile_classpath" refid="maven.compile.classpath" />
-
<property name="runtime_classpath" refid="maven.runtime.classpath" />
-
<property name="test_classpath" refid="maven.test.classpath" />
-
<property name="plugin_classpath" refid="maven.plugin.classpath" />
-
<property name="artifactId" value="${project.artifactId}" />
-
<property name="version" value="${project.version}" />
-
<property name="build.compiler" value="extJavac" />
-
<ant antfile="build.xml" target="dist" />
-
</tasks>
-
</configuration>
-
<goals>
-
<goal>run</goal>
-
</goals>
-
</execution>
-
</executions>
- </plugin>
build.compiler参数配置很重要,mvn默认使用的是jre,会导致ant无法正常编译
配置源代码路径:
点击(此处)折叠或打开
-
<sourceDirectory>${basedir}/src</sourceDirectory>
- <outputDirectory>${basedir}/classes</outputDirectory>
配置complile和外部jar包
点击(此处)折叠或打开
-
<plugin>
-
<artifactId>maven-compiler-plugin</artifactId>
-
<version>2.3.2</version>
-
<configuration>
-
<source>1.7</source>
-
<target>1.7</target>
-
<encoding>UTF-8</encoding>
-
<compilerArguments>
-
<extdirs>${basedir}/lib</extdirs>
-
</compilerArguments>
-
</configuration>
- </plugin>
配置checkstyle、pmd:
点击(此处)折叠或打开
-
<pluginManagement>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-checkstyle-plugin</artifactId>
-
<version>2.17</version>
-
<configuration>
-
<configLocation>sun_checks_eclipse.xml</configLocation>
-
</configuration>
-
<dependencies>
-
<dependency>
-
<groupId>com.puppycrawl.tools</groupId>
-
<artifactId>checkstyle</artifactId>
-
<version>6.17</version>
-
</dependency>
-
</dependencies>
-
</plugin>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-pmd-plugin</artifactId>
-
<version>3.6</version>
-
</plugin>
-
</plugins>
- </pluginManagement>
配置findbugs:
点击(此处)折叠或打开
-
<reporting>
-
<plugins>
-
<!--FindBugs插件。maven goal:findbugs:findbugs -->
-
<plugin>
-
<groupId>org.codehaus.mojo</groupId>
-
<artifactId>findbugs-maven-plugin</artifactId>
-
<version>3.0.3</version>
-
<configuration>
-
<effort>Default</effort>
-
<findbugsXmlOutput>true</findbugsXmlOutput>
-
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
-
<xmlOutput>true</xmlOutput>
-
</configuration>
-
</plugin>
-
</plugins>
- </reporting>
7.其他
如果项目之前没有使用checkstyle,再应用checkstyle,会发现大量的警告信息(我发现了几十万条)
这种情况,可以通过eclipse的checkstyle插件自定义符合自己项目的checkstyle配置
附pom.xml:
附pom.xml:
点击(此处)折叠或打开
-
<project>
-
<modelVersion>4.0.0</modelVersion>
-
<artifactId>project-A</artifactId>
-
<groupId>project-A-group</groupId>
-
<version>1.0</version>
-
<build>
-
<sourceDirectory>${basedir}/src</sourceDirectory>
-
<outputDirectory>${basedir}/classes</outputDirectory>
-
<plugins>
-
<plugin>
-
<artifactId>maven-antrun-plugin</artifactId>
-
<version>1.7</version>
-
<executions>
-
<execution>
-
<phase>generate-sources</phase>
-
<configuration>
-
<tasks>
-
<property name="compile_classpath" refid="maven.compile.classpath" />
-
<property name="runtime_classpath" refid="maven.runtime.classpath" />
-
<property name="test_classpath" refid="maven.test.classpath" />
-
<property name="plugin_classpath" refid="maven.plugin.classpath" />
-
<property name="artifactId" value="${project.artifactId}" />
-
<property name="version" value="${project.version}" />
-
<property name="build.compiler" value="extJavac" />
-
<ant antfile="build.xml" target="dist" />
-
</tasks>
-
</configuration>
-
<goals>
-
<goal>run</goal>
-
</goals>
-
</execution>
-
</executions>
-
</plugin>
-
<plugin>
-
<artifactId>maven-compiler-plugin</artifactId>
-
<version>2.3.2</version>
-
<configuration>
-
<source>1.7</source>
-
<target>1.7</target>
-
<encoding>UTF-8</encoding>
-
<compilerArguments>
-
<extdirs>${basedir}/lib</extdirs>
-
</compilerArguments>
-
</configuration>
-
</plugin>
-
</plugins>
-
<pluginManagement>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-checkstyle-plugin</artifactId>
-
<version>2.17</version>
-
<configuration>
-
<configLocation>sun_checks_eclipse.xml</configLocation>
-
</configuration>
-
<dependencies>
-
<dependency>
-
<groupId>com.puppycrawl.tools</groupId>
-
<artifactId>checkstyle</artifactId>
-
<version>6.17</version>
-
</dependency>
-
</dependencies>
-
</plugin>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-pmd-plugin</artifactId>
-
<version>3.6</version>
-
</plugin>
-
</plugins>
-
</pluginManagement>
-
</build>
-
<reporting>
-
<plugins>
-
<!--FindBugs插件。maven goal:findbugs:findbugs -->
-
<plugin>
-
<groupId>org.codehaus.mojo</groupId>
-
<artifactId>findbugs-maven-plugin</artifactId>
-
<version>3.0.3</version>
-
<configuration>
-
<effort>Default</effort>
-
<findbugsXmlOutput>true</findbugsXmlOutput>
-
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
-
<xmlOutput>true</xmlOutput>
-
</configuration>
-
</plugin>
-
</plugins>
-
</reporting>
- </project>