Jenkins安裝
下載jenkins.war包,運(yùn)行java -jar jenkins.war,即可訪問(wèn)http://localhost:8080/訪問(wèn)jenkins。
或者將jenkins.war包放在Tomcat的Webapp下,啟動(dòng)Tomcat,訪問(wèn)http://localhost:8080/jenkins/。
本例產(chǎn)用后者。
1. 在首頁(yè)選擇系統(tǒng)管理,再右側(cè)頁(yè)面中選擇管理插件。
在可選插件中選擇要安裝的插件,下表為本次測(cè)試中已安裝的插件,有些為默認(rèn)已安裝的插件。
插件
名稱
版本
啟用
Pinned
mailer |
1.4 |
true |
false |
external-monitor-job |
1.1 |
true |
false |
ldap |
1.1 |
true |
false |
pam-auth |
1.0 |
true |
false |
javadoc |
1.0 |
true |
false |
maven-plugin |
1.499 |
true |
false |
ant |
1.1 |
true |
false |
analysis-core |
1.48 |
true |
false |
checkstyle |
3.32 |
true |
false |
cvs |
1.6 |
true |
false |
deploy |
1.9 |
true |
false |
jquery |
1.7.2-1 |
true |
false |
junit-attachments |
1.3 |
true |
false |
ssh-slaves |
0.22 |
true |
false |
subversion |
1.39 |
true |
false |
translation |
1.8 |
true |
false |
email-ext |
2.25 |
true |
false |
|
2.進(jìn)入jenkins首頁(yè),選擇新建JOB,填寫一個(gè)JOB名稱,選擇“構(gòu)建一個(gè)自由風(fēng)格的軟件項(xiàng)目”。
然后進(jìn)入配置頁(yè)面,也可以首頁(yè)選擇項(xiàng)目,然后選擇配置進(jìn)入此頁(yè)面。
本例的配置如下:
1) 源碼管理選擇Subversion
Repository Url:https://localhost/svn/Diary/trunk/Diary
2) 構(gòu)建觸發(fā)器
選擇Poll SCM
日程表:* * * * * (表示每分鐘都比較,有更改就構(gòu)建)
3) 構(gòu)建
增加構(gòu)建步驟:Invoke Ant
Targets:(什么也沒(méi)寫,默認(rèn)執(zhí)行根目錄下的build.xml)
4) 構(gòu)建后操作
a. Publish Checkstyle analysis results
Checkstyle results:output/diary/checkstyle/checkstyle_report.xml
b. Publish JUnit test result report
Test report XMLs:output/diary/test/data/*.xml
保留長(zhǎng)的標(biāo)準(zhǔn)輸出/錯(cuò)誤 勾選
c. Publish Javadoc
Javadoc directory:output/diary/docs
d.Deploy war/ear to a container
WAR/EAR files:output/diary/diary-1.0.0.war
Container:Tomcat 6.x
Manager user name:admin
Manager password:*****
Tomcat URL:http://localhost:8080
(此處要配置Tomcat的角色和用戶:
在Tomcat的安裝目錄下,找到conf/tomcat-users.xml,修改內(nèi)容如下:
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="admin" password="admin" roles="admin,manager"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
)
e. Editable Email Notification
Project Recipient List:要發(fā)送的郵件,可多個(gè)用逗號(hào)隔開(kāi)
(此處要配置郵件服務(wù),選擇系統(tǒng)管理->系統(tǒng)設(shè)置:
Jenkins Location
Jenkins URL:http://localhost:8080/jenkins/
配置郵件通知
也可以Extended E-mail Notification中選擇Override Global Settings覆蓋的郵件通知。
在測(cè)試過(guò)程中,郵件通知中沒(méi)有“發(fā)送者的郵箱地址”這一項(xiàng),導(dǎo)致郵件一直不能發(fā)送,選擇了Extended E-mail Notification中的Override Global Settings,在這里填寫信息才將郵件發(fā)送成功。
)
附:
build.xml,增加War包:
001 | <?xml version= "1.0" encoding= "UTF-8" ?> |
002 | <project name= "diary" default= "total" > |
005 | <<a href= "http://www./program/" target= "_blank" ><u> for </u></a>mat property= "build.latest.dir" pattern= "yyyyMMddHHmmss" /> |
006 | <<a href= "http://www./program/" target= "_blank" ><u> for </u></a>mat property= "build.latest.date" pattern= "yyyy-MM-dd" /> |
007 | < format property= "build.latest.time" pattern= "HH:mm:ss" /> |
010 | <property name= "src.dir" location= "src" /> |
012 | <property name= "web.dir" location= "WebContent" /> |
014 | <property name= "we<a href=" http://www./linux/ " target=" _blank "><u>bin</u></a>f.dir" location= "${web.dir}/WEB-INF" /> |
016 | <property name= "lib.dir" location= "${we<a href=" http://www./linux/ " target=" _blank "><u>bin</u></a>f.dir}/lib" /> |
018 | <property name= "build.dir" location= "build/classes" /> |
021 | <property name= "build.output" location= "output" /> |
023 | <property name= "build.output.dir" location= "${build.output}/diary" /> |
026 | <property name= "build.output.doc.dir" location= "${build.output.dir}/docs" /> |
029 | <property name= "test.dir" location= "test" /> |
031 | <property name= "build.output.test.dir" location= "${build.output.dir}/test" /> |
033 | <property name= "build.output.test.data.dir" location= "${build.output.test.dir}/data" /> |
036 | <property name= "build.output.checkstyle.dir" location= "${build.output.dir}/checkstyle" /> |
038 | <property name= "checkstyle.xml" location= "${build.output.checkstyle.dir}/checkstyle_checks.xml" /> |
040 | <property name= "checkstyle.xsl" location= "${build.output.checkstyle.dir}/checkstyle-frames.xsl" /> |
043 | <property name= "build.output.log" location= "${build.output}/output.log" /> |
045 | <property name= "build.output.log.verbose" location= "${build.output}/output_verbose.log" /> |
047 | <property name= "build.output.log.datetime" value= "http://xuxujing./blog/[${build.latest.date} ${build.latest.time}]" /> |
050 | <property file = "${src.dir}/base.properties" /> |
052 | <property name= "build.output.requires.dir" location= "${build.output.dir}/requires" /> |
054 | <fileset id = "compile.jar" dir = "${lib.dir}" > |
055 | <include name= "commons-lang-2.4.jar" /> |
059 | <path id = "compile.classpath" > |
060 | <fileset refid= "compile.jar" /> |
063 | <path id = "test.classpath" > |
064 | <path refid= "compile.classpath" /> |
065 | <pathelement location= "${lib.dir}/junit-4.10.jar" /> |
066 | <pathelement location= "${build.dir}" /> |
069 | <path id = "checkstyle.classpath" > |
070 | <pathelement location= "${lib.dir}/checkstyle-5.6-all.jar" /> |
074 | <!-- 記錄日志,日志保存到文件中 --> |
075 | <record name= "${build.output.log}" append= "no" /> |
077 | <record name= "${build.output.log.verbose}" append= "no" loglevel= "verbose" /> |
079 | <target name= "total" depends= "zip,war" description= "構(gòu)建完成" > |
080 | < echo >${build.output.log.datetime}構(gòu)建完成!</ echo > |
083 | <target name= "war" depends= "createjar,javadoc" description= "生成War" > |
084 | <war destfile= "${build.output.dir}/${project.name}-${project.version}.war" webxml= "${webinf.dir}/web.xml" duplicate= "fail" > |
085 | <fileset file = "${web.dir}/*.jsp" /> |
086 | <lib dir = "${lib.dir}" > |
087 | <include name= "commons-lang-2.4.jar" /> |
089 | <classes dir = "${build.dir}" > |
090 | <include name= "diary/**/*" /> |
091 | <include name= "${build.dir}/test.property" /> |
094 | < echo >${build.output.log.datetime}生成War完成!</ echo > |
097 | <target name= "zip" depends= "createjar,javadoc" description= "生成Zip" > |
098 | <zip destfile= "${build.output.dir}/${project.name}-core-${project.version}.zip" duplicate= "preserve" > |
099 | <zipfileset dir = "${build.output.dir}/docs" prefix= "docs" /> |
100 | <zipfileset dir = "${build.output.dir}/requires" prefix= "requires" /> |
101 | <zipfileset file = "${build.output.dir}/*.jar" /> |
103 | < echo >${build.output.log.datetime}生成Zip完成!</ echo > |
106 | <target name= "createjar" depends= "test" description= "生成Jar" > |
107 | <manifest file = "${build.output.dir}/MANIFEST.MF" encoding= "utf-8" > |
109 | <section name= "${project.name}" > |
114 | <jar destfile= "${build.output.dir}/${project.name}-core-${project.version}.jar" duplicate= "preserve" compress= "false" manifestencoding= "utf-8" manifest= "${build.output.dir}/MANIFEST.MF" > |
115 | <fileset dir = "${build.dir}" > |
116 | <exclude name= "test/**/*" /> |
117 | <exclude name= "test" /> |
118 | <exclude name= "checkstyle_checks.xml" /> |
119 | <exclude name= "checkstyle-frames.xsl" /> |
120 | <exclude name= "checkstyletask.properties" /> |
121 | <exclude name= "sun_checks.xml" /> |
122 | <exclude name= "checkstyle_checks.xml" /> |
123 | <exclude name= "base.properties" /> |
126 | <copy todir= "${build.output.requires.dir}" > |
127 | <fileset refid= "compile.jar" /> |
129 | < echo >${build.output.log.datetime}生成Jar完成!</ echo > |
132 | <target name= "javadoc" depends= "test" description= "生成JavaDoc" > |
134 | sourcepath= "${src.dir}" |
135 | destdir= "${build.output.doc.dir}" |
136 | packagenames= "diary.*" |
139 | windowtitle= "${project.name}" |
141 | <classpath refid= "compile.classpath" /> |
143 | < echo >${build.output.log.datetime}生成JavaDoc完成,詳情可查看${build.output.doc. dir }/index.html!</ echo > |
146 | <target name= "test" depends= "compilesrc,compiletest" description= "批量測(cè)試,并生成html" > |
147 | <junit printsummary= "false" haltonfailure= "false" errorProperty= "test.failed" failureProperty= "test.failed" > |
148 | <classpath refid= "test.classpath" /> |
149 | <formatter type = "brief" usefile= "false" /> |
150 | <formatter type = "xml" /> |
151 | <!-- 在testcase定義的情況下,單獨(dú)測(cè)試testcase --> |
152 | < test name= "${testcase}" todir= "${build.output.test.data.dir}" if = "testcase" /> |
154 | <batchtest todir= "${build.output.test.data.dir}" unless= "testcase" > |
155 | <fileset dir = "${build.dir}" > |
156 | <include name= "**/*Test.class" /> |
160 | <junitreport todir= "${build.output.test.data.dir}" > |
161 | <fileset dir = "${build.output.test.data.dir}" > |
162 | <include name= "TEST-*.xml" /> |
164 | <report format = "frames" todir= "${build.output.test.dir}" /> |
166 | <fail if = "test.failed" > |
167 | ${build.output.log.datetime}批量測(cè)試,并生成html失敗,詳細(xì)可查看${build.output. test . dir }/index.html |
169 | < echo >${build.output.log.datetime}批量測(cè)試,并生成html完成,詳細(xì)可查看${build.output. test . dir }/index.html!</ echo > |
172 | <target name= "compiletest" depends= "copytest,compilesrc" description= "<a href=" http://www./linux/ " target=" _blank "><u>編譯</u></a>測(cè)試<a href=" http://www./program/ " target=" _blank "><u>代碼</u></a>文件" > |
173 | <javac srcdir= "${test.dir}" destdir= "${build.dir}" includeAntRuntime= "false" encoding= "UTF-8" > |
174 | <include name= "**/*.java" /> |
175 | <classpath refid= "test.classpath" /> |
180 | <target name= "copytest" depends= "init" description= "復(fù)制測(cè)試代碼資源文件到編譯目錄" > |
181 | <fileset dir = "${test.dir}" > |
182 | <exclude name= "**/*.java" /> |
184 | < echo >${build.output.log.datetime}復(fù)制測(cè)試代碼資源文件到編譯目錄完成!</ echo > |
187 | <target name= "compilesrc" depends= "checkstyle,copysrc" description= "編譯源代碼文件" > |
188 | <javac srcdir= "${src.dir}" destdir= "${build.dir}" includeAntRuntime= "false" encoding= "UTF-8" > |
189 | <include name= "**/*.java" /> |
190 | <classpath refid= "compile.classpath" /> |
192 | < echo >${build.output.log.datetime}編譯源代碼文件完成!</ echo > |
195 | <target name= "copysrc" depends= "init" description= "復(fù)制源代碼資源文件到編譯目錄" > |
196 | <copy todir= "${build.dir}" includeemptydirs= "false" > |
197 | <fileset dir = "${src.dir}" > |
198 | <exclude name= "**/*.java" /> |
201 | < echo >${build.output.log.datetime}復(fù)制源代碼資源文件到編譯目錄完成!</ echo > |
204 | <target name= "checkstyle" depends= "init" description= "用Checkstyle校驗(yàn)源代碼" > |
207 | failOnViolation= "false" |
208 | failureProperty= "checkstyle.failed" |
209 | config= "${src.dir}/sun_checks.xml" > |
210 | <fileset dir = "${src.dir}" includes= "**/*.java" /> |
211 | <formatter type = "plain" /> |
212 | <formatter type = "xml" toFile= "${build.output.checkstyle.dir}/checkstyle_report.xml" /> |
214 | <xslt style= "${checkstyle.xsl}" |
215 | in = "${build.output.checkstyle.dir}/checkstyle_report.xml" |
216 | out= "${build.output.checkstyle.dir}/checkstyle_report.html" > |
218 | < echo >${build.output.log.datetime}用Checkstyle校驗(yàn)源代碼完成,詳細(xì)信息查看${build.output.checkstyle. dir }/checkstyle_report.html!</ echo > |
221 | <target name= "init" depends= "clean,cleanoutput" description= "創(chuàng)建輸出目錄" > |
222 | < mkdir dir = "${build.dir}" /> |
223 | < mkdir dir = "${build.output.dir}" /> |
224 | < mkdir dir = "${build.output.doc.dir}" /> |
225 | < mkdir dir = "${build.output.test.dir}" /> |
226 | < mkdir dir = "${build.output.test.data.dir}" /> |
227 | < mkdir dir = "${build.output.checkstyle.dir}" /> |
228 | <copy todir= "${build.output.checkstyle.dir}" overwrite= "true" > |
229 | <fileset dir = "${src.dir}" > |
230 | <include name= "checkstyle-frames.xsl" /> |
231 | <include name= "checkstyle_checks.xml" /> |
237 | < echo >${build.output.log.datetime}輸出目錄創(chuàng)建完成!</ echo > |
240 | <target name= "clean" description= "清理編譯目錄" > |
241 | <delete includeemptydirs= "true" > |
242 | <fileset dir = "${build.dir}" > |
243 | <include name= "**/*" /> |
246 | < echo >${build.output.log.datetime}編譯目錄清理完成!</ echo > |
249 | <target name= "cleanoutput" description= "清理輸出目錄" > |
250 | <delete includeemptydirs= "true" > |
251 | <fileset dir = "${build.output}" > |
252 | <exclude name= "output*.log" /> |
255 | < echo >${build.output.log.datetime}輸出目錄清理完成!</ echo > |
輸出:
構(gòu)建出錯(cuò)后的輸出,會(huì)發(fā)送郵件到指定郵箱:
03 | Started by user anonymous |
04 | Building in workspace C:\Users\xujing\.jenkins\jobs\Diary\workspace |
08 | No emails were triggered. |
09 | [workspace] $ cmd.exe /C '"ant.bat && exit %%ERRORLEVEL%%"' |
10 | Buildfile: C:\Users\xujing\.jenkins\jobs\Diary\workspace\build.xml |
13 | [ echo ] [2013-01-21 15:50:49] 編譯目錄清理完成! |
16 | [ echo ] [2013-01-21 15:50:49] 輸出目錄清理完成! |
19 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary |
20 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs |
21 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\ test |
22 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\ test \data |
23 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle |
24 | [copy] Copying 2 files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle |
25 | [ echo ] [2013-01-21 15:50:49] 輸出目錄創(chuàng)建完成! |
28 | [checkstyle] Running Checkstyle 5.6 name= "code" >控制臺(tái)輸出 |
30 | Started by user anonymous |
31 | Building in workspace C:\Users\xujing\.jenkins\jobs\Diary\workspace |
35 | No emails were triggered. |
36 | [workspace] $ cmd.exe /C '"ant.bat && exit %%ERRORLEVEL%%"' |
37 | Buildfile: C:\Users\xujing\.jenkins\jobs\Diary\workspace\build.xml |
40 | [ echo ] [2013-01-21 16:21:25] 編譯目錄清理完成! |
43 | [ echo ] [2013-01-21 16:21:25] 輸出目錄清理完成! |
46 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary |
47 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs |
48 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\ test |
49 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\ test \data |
50 | [ mkdir ] Created dir : C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle |
51 | [copy] Copying 2 files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle |
52 | [ echo ] [2013-01-21 16:21:25] 輸出目錄創(chuàng)建完成! |
55 | [checkstyle] Running Checkstyle 5.6> |
59 | <li>Diary.zip (3.1 MB)</li> |
73 | <center><div style= "margin:10px 0 25px 0" > |
74 | <script type = "text/javascript" > |
75 | /*500*200,創(chuàng)建于2013-4-2 07net01 文章內(nèi)部下*/ |
76 | var cpro_id = "u1251111" ; |
|