Linux环境 搭建Jenkins+SVN+Maven持续集成环境

准备
操作系统:Linux

环境:JDK 1.6+

文件:

jenkins.war

apache-maven-3.1.1

apache-tomcat-6.0.xx

一、部署Jenkins

1.复制tomcat,命名为jenkins-server,删除jenkins-server的webapps中全部文件,把jenkins.war移动到webapps中,重命名为ROOT.war。

2.修改server.xml配置,修改端口,默认8080端口改为8070,shutdown端口改为8075,AJP端口改为8079。端口号根据个人习惯偏好设置,不与其他端口冲突即可。另外,在Connector中添加URIEncoding=”UTF-8″。


3.启动Jenkins,执行jenkins-server/bin中./startup.sh,访问 http://192.168.1.x:8070/,进入如下图页面。

<Server port="8075" shutdown="SHUTDOWN">
 
<Connector port="8070" protocol="HTTP/1.1" URIEncoding="UTF-8" 
               connectionTimeout="20000" 
               redirectPort="8443" />
 
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8079" protocol="AJP/1.3" redirectPort="8443" />

 


二、配置SVN

Jenkins默认集成了SVN插件。创建任务时,在源码管理中选择Subversion,然后填写Repository URL即可。

第一次需要填写SVN账号和密码。



三、手动配置Maven

1. 解压缩apache-maven-3.1.1-bin.tar.gz,(命令:tar -xvf apache-maven-3.1.1-bin.tar.gz)

2. 修改settings.xml,配置本地仓库路径,私服地址,及私服账号(用于发布文件至私服)

<!-- 本地仓库,此处使用相对路径 -->
<localRepository>../repository</localRepository>

<!-- 私服配置 -->
<profiles>
    <profile>
        <id>myprofile</id>
        <repositories>
            <repository>
                <id>nexus</id>
                <name>local nexus</name>
                <url>http://192.168.1.x:8081/nexus/content/groups/public/</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>nexus</id>
                <name>local nexus</name>
                <url>http://192.168.1.x:8081/nexus/content/groups/public/</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>

<!-- 私服账号配置,可选 -->
<!-- id对应工程pom.xml中distributionManagement下的repository,用于发布文件至私服仓库 --> 
<servers>
    <server>
      <id>nexus-release</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
</servers>

 
3. 配置Maven环境变量

修改/etc/profile文件,添加配置

export MAVEN_HOME=/app/liubo/tools/apache-maven-3.1.1/
export MAVEN_OPTS="-Xms256m -Xmx512m"
export PATH=${PATH}:${MAVEN_HOME}/bin

 
保存文件,并运行如下命令使环境变量生效

在控制台输入如下命令,如果能看到Maven相关版本信息,则说明Maven环境变量已经配置成功

mvn -v

 
4. 在Jenkins中手动配置Maven

打开“系统管理”->“系统配置”->“Maven”-> “Maven安装…”,不勾选“自动安装”,在MAVEN_HOME中填写maven路径,然后保存。




构建任务
1. 点击“新Job”,输入名称,勾选“构建一个maven2/3项目”。

2. 配置SVN:在“源码管理”中勾选“Subversion”,在Repository URL中填写SVN地址。

3. 配置Maven:在“Build”-> “Goals and options”填写下面内容(清理 、打包 、 跳过单元测试)

clean package -Dmaven.test.skip=true

 

4. 保存后,点击“立即构建”,可以在“Build History”中查看构建信息。





—-  END —-

猜你喜欢

转载自neo19860208.iteye.com/blog/1992969