本文主要根据Jenkins上的日志来继续说明构建项目的过程,上文我们已经讲到构建一个测试环境或单独终端的过程,详情可以了解上篇文章
一、背景介绍
首先看下SVN代码的仓库的结构:
代码仓库里有一个文件夹,可以随便取名,文件夹中可以放置很多单独的项目,每个项目下有branch,trunk,demand三个文件。在branch下面可以有pc端,微信端,
APP端,后台等终端,从下面的结构中,可以看出每个终端的代码中有资源文件夹src(类的定义,配置文件,说明文档,jar包等)和pom文件。
二、构建trunk项目
当发布正式环境时需先先构建trunk,然后发布正式项目,因此此时需要注意,如果有项目功能没有写完,不能直接构建trunk,此时构建trunk会将仓库下所有项目修改或更新的部分全部更新到Jenkins工作目录中。
1、Jenkins中的SVN地址:
构建正式环境:需要构建trunk,将代码仓库中所有变动的代码和Jenkins工作目录中的代码对比,然后更新Jenkins工作目录的代码
3.4版本trunk地址
https://101.21.101.111:443/svn/代码仓库/branches/qianrongyiV3.4(项目下有web,APP,WeChat等终端)
.4版本正式项目地址:
https://101.21.101.111:443/svn/代码仓库/branches/qianrongyiV3.4/qian-web(pom文件)(单独web终端) 构建预发布环境:不需要构建trunk,只需要单独构建项目即可,将单独项目变动部分更新。
.4版本预发布环境:
https://101.21.101.111:443/svn/代码仓库/branches/qianrongyiV3.4/qian-app
2、构建3.4版本trunk的过程:
Started by user @qq.com
Building in workspace /bat/jenkins/workspace/3.4-pro-trunk ##在Jenkins工作目录中更新3.-pro-trunk,如果没有这个文件夹,则创建。
Updating https://101.21.101.111:443/svn/代码仓库/branches/qianrongyiV3.4 at revision '2018-02-08T17:49:41.934 +0800'
下面内容表示更新Jenkins工作目录中项目的内容(根据SVN仓库中的文件与Jenkins工作目录中的文件对比),U表示更新;A表示添加;D表示删除。
U(update)qianee-common/src/main/java/com/test/qianee/constants/Constants.java(全路径为:/bat/jenkins/workspace/3.4-pro-trunk/qianee-common/src/main/java/com/test/qianee/constants/Constants.java;下面路径相同)
A(add) qianee-service/src/main/java/com/test/qianee/service/StatisticPlatformIncomeServiceImpl.java
U qianee-service/src/main/java/com/test/qianee/service/CapitalmanagerService.java
A qianee-service/src/main/java/com/test/qianee/service/ContentAdvertisementsLinksImple.java
D(delete) qianee-service/src/main/java/com/test/qianee/service/impl/ContentAdvertisementsLinksImple.java
D qianee-service/src/main/java/com/test/qianee/service/impl/StatisticPlatformIncomeServiceImpl.java At revision Parsing POMs ##开始分析pom文件
Established TCP socket on
[3.4-pro-trunk] $ java -cp /bat/jenkins/plugins/maven-plugin/WEB-INF/lib/maven32-agent-1.7.jar:/bat/maven/boot/plexus-classworlds-2.5..jar:/bat/maven/conf/logging jenkins.maven3.agent.Maven32Main /bat/maven /bat/webapps/jenkins/WEB-INF/lib/remoting-2.59.jar /bat/jenkins/plugins/maven-plugin/WEB-INF/lib/maven32-interceptor-1.7.jar /bat/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.7.jar ##指明了执行这个class文件所需要的所有类的包路径-即系统类加载器的路径
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven: -B -f /bat/jenkins/workspace/3.4-pro-trunk/pom.xml clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order: ##反应堆(Reactor)是一个包含了所有需要构建模块的抽象概念;模块会被包含到反应堆;反应堆中所有模块的构建顺序
[INFO]
[INFO] qianee
[INFO] qianee-wechat-service
[INFO] qianee-talent-wechat-service 项目二: [INFO] ------------------------------------------------------------------------
[INFO] Building qianee-wechat-service 3.4-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ##加载maven清理插件,清除Jenkins工作目录下项目的target已编译文件
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ qianee-wechat-service ---
[INFO] Deleting /bat/jenkins/workspace/3.4-pro-trunk/qianee-wechat-service/target
[INFO] ##为了使项目结构更为清晰,Maven区别对待Java代码文件和资源文件,maven-compiler-plugin用来编译Java代码,maven-resources-plugin则用来处理资源文件。 默认的主资源文件目录是src/main/resources,很多用户会需要添加额外的资源文件目录,这个时候就可以通过配置maven-resources-plugin来实现。
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ qianee-wechat-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ qianee-wechat-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling source files to /bat/jenkins/workspace/3.4-pro-trunk/qianee-wechat-service/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ qianee-wechat-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ qianee-wechat-service ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.:test (default-test) @ qianee-wechat-service ---
[JENKINS] Recording test results
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ qianee-wechat-service ---
[INFO] Building jar: /bat/jenkins/workspace/3.4-pro-trunk/qianee-wechat-service/target/qianee-wechat-service.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ qianee-wechat-service ---
[INFO] Installing /bat/jenkins/workspace/3.4-pro-trunk/qianee-wechat-service/target/qianee-wechat-service.jar to /root/.m2/repository/com/test/qianee/qianee-wechat-service/3.4-SNAPSHOT/qianee-wechat-service-3.4-SNAPSHOT.jar
[INFO] Installing /bat/jenkins/workspace/3.4-pro-trunk/qianee-wechat-service/pom.xml to /root/.m2/repository/com/test/qianee/qianee-wechat-service/3.4-SNAPSHOT/qianee-wechat-service-3.4-SNAPSHOT.pom -------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.test.qianee.app.WelcomeApiControllerTest ##运行app登录控制类测试
-- -- [main] [org.springframework.test.context.web.WebTestContextBootstrapper] [INFO] - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@36ecb8fa, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@6f644141, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1ef84b89, org.springframework.test.context.support.DirtiesContextTestExecutionListener@3f271f41]
-- -- [main] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] [INFO] - Loading XML bean definitions from class path resource [TestContext.xml]
........(省略数行)......
==============loaded properties files=================
file [/bat/jenkins/workspace/3.4-pro-trunk/qianee-app/target/classes/application-sms.properties]
.......(省略数行).........
Results : ##几个类的测试结果 Tests in error:
test(com.test.qianee.app.UserApiControllerTest): Result{status=, msg='该手机号尚未注册,请重新输入或注册', bat=null, msgMap=null}
。。。。。。(省略数行)。。。。。 Tests run: , Failures: , Errors: , Skipped: [ERROR] There are test failures. Please refer to /bat/jenkins/workspace/3.4-pro-trunk/qianee-app/target/surefire-reports for the individual test results.
[JENKINS] Recording test results
[INFO] ##APP项目打包
[INFO] --- maven-war-plugin:2.2:war (default-war) @ qianee-app ---
[INFO] Packaging webapp
[INFO] Assembling webapp [qianee-app] in [/bat/jenkins/workspace/3.4-pro-trunk/qianee-app/target/qianee-app]
[INFO] Processing war project
[INFO] Copying webapp resources [/bat/jenkins/workspace/3.4-pro-trunk/qianee-app/src/main/webapp]
[INFO] Webapp assembled in [ msecs]
[INFO] Building war: /bat/jenkins/workspace/3.4-pro-trunk/qianee-app/target/qianee-app.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ qianee-app ---
[INFO] Installing /bat/jenkins/workspace/3.4-pro-trunk/qianee-app/target/qianee-app.war to /root/.m2/repository/com/test/qianee/qianee-app/3.4-SNAPSHOT/qianee-app-3.4-SNAPSHOT.war
[INFO] Installing /bat/jenkins/workspace/3.4-pro-trunk/qianee-app/pom.xml to /root/.m2/repository/com/test/qianee/qianee-app/3.4-SNAPSHOT/qianee-app-3.4-SNAPSHOT.pom
[INFO]
。。。。。。(省略数行)。。。。。 、
[INFO] Reactor(反应器) Summary:
[INFO]
[INFO] qianee-web ......................................... SUCCESS [ 16.531 s]
[INFO] qianee-wechat-service .............................. SUCCESS [ 2.053 s]
[INFO] qianee-talent-wechat-service ....................... SUCCESS [ 1.889 s] [INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: : min
[INFO] Finished at: --08T17::+:
[INFO] Final Memory: 76M/557M
[INFO] ---------------------------项目存档---------------------------------------------
项目一存档:(将Jenkins工作目录中的war包和pom.xml文件存档备份到用户家目录下)
[JENKINS] Archiving(存档,归档) /bat/jenkins/workspace/3.4-pro-trunk/qianee-web/pom.xml to com.test.qianee/qianee-web/3.4-SNAPSHOT/qianee-web-3.4-SNAPSHOT.pom
[JENKINS] Archiving /bat/jenkins/workspace/3.4-pro-trunk/qianee-web/target/qianee-web.war to com.test.qianee/qianee-web/3.4-SNAPSHOT/qianee-web-3.4-SNAPSHOT.war
项目二存档:
[JENKINS] Archiving /bat/jenkins/workspace/3.4-pro-trunk/qianee-talent-wechat-service/pom.xml to com.test.qianee/qianee-talent-wechat-service/3.4-SNAPSHOT/qianee-talent-wechat-service-3.4-SNAPSHOT.pom
[JENKINS] Archiving /bat/jenkins/workspace/3.4-pro-trunk/qianee-talent-wechat-service/target/qianee-talent-wechat-service.jar to com.test.qianee/qianee-talent-wechat-service/3.4-SNAPSHOT/qianee-talent-wechat-service-3.4-SNAPSHOT.jar
项目三存档:
[JENKINS] Archiving /bat/jenkins/workspace/3.4-pro-trunk/qianee-wechat-service/pom.xml to com.test.qianee/qianee-wechat-service/3.4-SNAPSHOT/qianee-wechat-service-3.4-SNAPSHOT.pom
[JENKINS] Archiving /bat/jenkins/workspace/3.4-pro-trunk/qianee-wechat-service/target/qianee-wechat-service.jar to com.test.qianee/qianee-wechat-service/3.4-SNAPSHOT/qianee-wechat-service-3.4-SNAPSHOT.jar
。。。。。。(省略数行)。。。。。
channel stopped
Finished: UNSTABLE
3、Jenkins上trunk配置:
部分1、Maven project name 栏设置
主要填写Maven project name(工程名)、Descript(工程描述信息)
部分2、Source Code Management 栏设置
输入源码的获取地址,由于我的插件中演示的是svn,那么如下输入:
Repository depth: Jenkins在执行checkout、update代码时,所取出的代码的范围。默认我们选择infinity就可以。
Check-out Strategy:svn第一次更新代码和以后同步代码的步骤,和策略。默认选项一般就可以。
部分3、Build Triggers 栏设置
默认选项为:
Build whenever a SNAPSHOT dependency is buil 意思就是svn更新触发构建
这里建议选择:
Poll SCM 相当于新建一个计划任务,定时检查版本库,发现有新的提交就触发构建。其配置的意思和linux的crontab差不多,如10分钟构建一次
部分4、Build 栏设置
如果对mvn构建参数有需求,或者需要设置pom.xml的文件位置,可以在这里设置。
默认: pom.xml的文件就在工程目录下。
部分5、完成
点 save 完成对一个一个工程的设置