Jenkins+SVN+tomcat持續集成發佈

有代碼更新後從新打包到tomcat再發布,是否是很煩?html

看了下面的東西你就不會煩了。 java

 

SVN或者git等代碼版本控制工具不說了,若是是本地開發,也能夠安裝一個svn server端git

 

jenkins下載後是一個war包,web

首先設置下 環境變量   JENKINS_HOME  爲 c:\jenkinsapache

拷貝到一個tomcat的webapp目錄下啓動tomcat保證能正常訪問tomcat

http://localhost:8880/jenkins/  多個tomcat請注意修改端口服務器

 

打開後第一次沒任何項目,新建一個項目   maven項目,怎麼建立maven項目  請參考個人博客其餘文章app

 

必填項:webapp

項目名稱:   隨意了,本身喜歡就好 O(∩_∩)O哈哈~socket

下面填寫本身的svn cvs等信息,地址及用戶名密碼

 

 

往下: 請勾選  Build whenever a SNAPSHOT dependency is built 這個複選框

 

再往下就是配置構建成功後發佈信息的,這個首先得安裝一個插件

安裝Deploy to container Plugin 插件,安裝成功後才能自動發佈

 

安裝好後重啓下服務器最好

 

構建後操做,選擇安裝好插件後的 deploy war to container,

輸入target目錄下生成的war包,

 

配置遠程的tomcat,並保證能夠登陸到manage界面,配置的tomcat處於啓動狀態

 

 

注意:

tomcat默認是沒有用戶能夠登陸的  須要修改 conf下的user.xml

以下:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-jmx"/>
  <role rolename="manager-status"/>
  <user password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status" username="tomcat"/>
</tomcat-users>

 

同時記得修改tomcat/conf/context.xml

<Context antiResourceLocking="true"> 

修改這個主要是爲了解決再次部署的時候,不能刪除原項目部署目錄,詳情可參考 http://tomcat.apache.org/tomcat-7.0-doc/config/context.html 搜索 lock

 

配置完成,點擊應用  保存

而後建立,失敗是紅色,具體信息看控制檯,成功後的log大體以下:

Started by user anonymous
Building in workspace c:\jenkins\workspace\demo
Updating https://xiaochangwei/svn/demo1/Test001 at revision '2015-11-10T12:59:10.009 +0800'
At revision 7
no change for https://xiaochangwei/svn/demo1/Test001 since the previous build
Parsing POMs
Established TCP socket on 51539
[demo] $ "C:\Program Files\Java\jdk1.7.0_80/bin/java" -cp c:\jenkins\plugins\maven-plugin\WEB-INF\lib\maven32-agent-1.7.jar;C:\work\software\apache-maven-3.3.3\boot\plexus-classworlds-2.5.2.jar;C:\work\software\apache-maven-3.3.3/conf/logging jenkins.maven3.agent.Maven32Main C:\work\software\apache-maven-3.3.3 C:\apache-tomcat-7.0.64\webapps\jenkins\WEB-INF\lib\remoting-2.52.jar c:\jenkins\plugins\maven-plugin\WEB-INF\lib\maven32-interceptor-1.7.jar c:\jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.7.jar 51539
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f c:\jenkins\workspace\demo\pom.xml install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Test001 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Test001 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Test001 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Test001 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Test001 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Test001 ---
[JENKINS] Recording test results
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ Test001 ---
[INFO] Packaging webapp
[INFO] Assembling webapp [Test001] in [c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [c:\jenkins\workspace\demo\src\main\webapp]
[INFO] Webapp assembled in [41 msecs]
[INFO] Building war: c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ Test001 ---
[INFO] Installing c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war to c:\wis_mvn_repo\com\xiao\Test001\0.0.1-SNAPSHOT\Test001-0.0.1-SNAPSHOT.war
[INFO] Installing c:\jenkins\workspace\demo\pom.xml to c:\wis_mvn_repo\com\xiao\Test001\0.0.1-SNAPSHOT\Test001-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.192 s
[INFO] Finished at: 2015-11-10T12:59:18+08:00
[INFO] Final Memory: 17M/226M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving c:\jenkins\workspace\demo\pom.xml to com.xiao/Test001/0.0.1-SNAPSHOT/Test001-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war to com.xiao/Test001/0.0.1-SNAPSHOT/Test001-0.0.1-SNAPSHOT.war
channel stopped
[WARNING] Couldn't clean up oid=3 from null
hudson.remoting.ChannelClosedException: channel is already closed
	at hudson.remoting.Channel.send(Channel.java:575)
	at hudson.remoting.RemoteInvocationHandler$PhantomReferenceImpl.cleanup(RemoteInvocationHandler.java:360)
	at hudson.remoting.RemoteInvocationHandler$PhantomReferenceImpl.access$700(RemoteInvocationHandler.java:319)
	at hudson.remoting.RemoteInvocationHandler$Unexporter.run(RemoteInvocationHandler.java:420)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at hudson.remoting.AtmostOneThreadExecutor$Worker.run(AtmostOneThreadExecutor.java:110)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException
	at hudson.remoting.Channel.close(Channel.java:1160)
	at hudson.remoting.Channel.close(Channel.java:1135)
	at hudson.remoting.Channel$CloseCommand.execute(Channel.java:1076)
	at hudson.remoting.Channel$1.handle(Channel.java:498)
	at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:60)
Deploying c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war to container Tomcat 7.x Remote
  [c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war] is not deployed. Doing a fresh deployment.
  Deploying [c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war]
Finished: SUCCESS

 

打開tomcat管理頁面都能看見發佈的項目

 

一樣打開這個項目也能正常訪問

 

jdk maven配置:

 

若是碰見編碼問題

1.增長環境變量   JAVA_TOOL_OPTIONS= -Dfile.encoding=UTF-8

2.在kenkins中增長Environment variables   LANG=zh.CH.UTF-8 和 JAVA_TOOL_OPTIONS= -Dfile.encoding=UTF-8

相關文章
相關標籤/搜索