Jenkins+ Maven+Svn

Jenkins是一个可扩展的持续集成引擎,Jenkins非常易于安装和配置,简单易用(可我在实际配置的时候却不是那么简单),下面我们来看看如何配置吧

服务器版本:Redhat 6.4-64

一、安装Jenkins

  1. 安装resin,这个就不讲了,或者使用Tomcat

  2. 安装maven,这个也不讲了

  3. 安装jenkins

下载地址:http://mirrors.jenkins-ci.org/  下载适合的jenkins版本

  1. jenkins解压,把得到的war包直接放在resin或者tomcat,jenkins就安装完毕,

 

二、配置Jenkins

1.打开http://192.168.30.44:8080/,第一次进入里面没有数据,我们需要创建job,

2.点击左上角的新建,在新建页面选择新建的类型,jenkins支持几种类型,我们需要选择构建一个maven2/3项目”,项目名为test

 Jenkins+Maven+svn 安装使用指南_jenkins

3.点击Ok按钮后,会进入详细配置界面,详细配置界面的配置项很多,下面说说几个需要配置的地方

3.1)项目名称就不用修改了,

丢弃旧的构建选上,保持构建的最大个数根据自已的喜好填写就好,不写亦可,在这里我写的是2

Jenkins+Maven+svn 安装使用指南_ svn_02

3.2)参数化构建过程,这个必须选上,我选择的是Choice.   Choices里的东西是需要编译执行的脚本:mvn cleandependency:copy-dependencies -DoutputDirectory=lib package install

Jenkins+Maven+svn 安装使用指南_ svn_03

3.3)源码管理,这里我使用的是svn。就选择了Subversion

Repository URL 填写的是项目在svn的目录

Local module directory(optional)填写的是在服务器的目录,默认应该是在服务器的/root/.jenkins/workspace/ 目录下

Jenkins+Maven+svn 安装使用指南_ svn_04

3.4)构建触发器

这里我选择的是第一个 Build whenever a SNAPSHOT dependency is built

构建环境没有选择

Pre Steps 点击下方的Add pre-buildstep->Execute shell

Command 中写你需要执行的脚本,这个脚本是编译之前执行的,切记

Jenkins+Maven+svn 安装使用指南_maven_05

3.5)Post Steps

点击Add post-build step->Execute shell

Command 中写你需要执行的脚本,这个脚本是在项目编译完成后执行的,切记

Jenkins+Maven+svn 安装使用指南_jenkins _06

3.6)最后一项我没有做任何修改,也没必要修改

Jenkins+Maven+svn 安装使用指南_ svn_07

配置完后点击保存即可

 

三、全局配置

1.点击左边的系统管理->点击系统设置

1.1)这里主要设置下maven的配置文件

Jenkins+Maven+svn 安装使用指南_maven_08

1.2)JDK是必须安装的

Jenkins+Maven+svn 安装使用指南_ svn_09

1.3)Ant 如果你用就安装,不用就算了,但是maven是必须的,

Jenkins+Maven+svn 安装使用指南_ svn_10

1.4)这里是一些简单的配置,看看就好

Jenkins+Maven+svn 安装使用指南_ svn_11

1.5)以下是一些无关紧要的

Jenkins+Maven+svn 安装使用指南_ svn_12

1.6)配置完点击保存即可

1.7)系统管理->ConfigureGlobal Security

Jenkins+Maven+svn 安装使用指南_maven_13

 

四、修改/usr/local/maven/conf/settings.xml

我使用的是本地的私服,内容如下:

<?xml version="1.0"encoding="UTF-8"?>

 

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0http://maven.apache.org/xsd/settings-1.0.0.xsd">

       <!-- 本地仓库 -->

       <localRepository>/usr/local/jenkins/maven/repository</localRepository>

 

       <interactiveMode>true</interactiveMode>

 

       <offline>false</offline>

 

       <pluginGroups></pluginGroups>

 

       <proxies></proxies>

 

       <servers>

                <server>

                       <id>user-snapshots</id>

                       <username>deployment</username>

                       <password>deployment123</password>

                </server>

                <server>

                       <id>user-releases</id>

                       <username>deployment</username>

                       <password>deployment123</password>

                </server>

                <server>

                       <id>thirdparty</id>

                       <username>deployment</username>

                       <password>deployment123</password>

                </server>

       </servers>

 

<!--

       <mirrors>

                <mirror>

                       <id>nexus</id>

                       <mirrorOf>central</mirrorOf>

                        <name>使用私库替换maven预定义的centra仓库</name>

                       <url>http://192.168.30.46:8081/nexus/content/groups/public/</url>

                </mirror>

       </mirrors>

-->

       <profiles>

                <profile>

                       <id>dev</id>

                        <repositories>

                               <repository>

                                       <id>nexus</id>

                                       <url>http://192.168.30.46:8081/nexus/content/groups/public/</url>

                                       <releases>

                                               <enabled>true</enabled>

                                       </releases>

                                       <snapshots>

                                               <enabled>true</enabled>

                                       </snapshots>

                               </repository>

                        </repositories>

                       <pluginRepositories>

                               <pluginRepository>

                                       <id>nexus</id>

                                       <url>http://192.168.30.46:8081/nexus/content/groups/public/</url>

                                        <releases>

                                               <enabled>true</enabled>

                                       </releases>

                                       <snapshots>

                                               <enabled>true</enabled>

                                       </snapshots>

                               </pluginRepository>

                       </pluginRepositories>

                </profile>

 

                <profile>

                       <id>jdk-1.6</id>

                       <activation>

                               <activeByDefault>true</activeByDefault>

                               <jdk>1.6</jdk>

                        </activation>

                        <properties>

                                <maven.compiler.source>1.6</maven.compiler.source>

                               <maven.compiler.target>1.6</maven.compiler.target>

                               <maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>

                        </properties>

                </profile>

       </profiles>

 

       <activeProfiles>

               <activeProfile>dev</activeProfile>

       </activeProfiles>

</settings>

 

 

 

Pom.xml 文件

东西太多了,我只修改了一下私服:

<repositories>

                   <repository>

                            <id>nexus</id>

                            <name>TeamNexus Repository</name>

                            <url>http://192.168.30.44:8081/nexus/content/groups/public</url>

                            <releases>

                                     <enabled>true</enabled>

                        </releases>

                       <snapshots>

                                     <enabled>true</enabled>

                       </snapshots>

                </repository>

 

         </repositories>