1. 程式人生 > >Jenkins (自動化發布)

Jenkins (自動化發布)

自動 謝謝 nco content bubuko color pac tail 1.0

首先咱們需要安裝一個 Jenkins,這個就不必多說了,晚上一搜索一大把,然後安裝各種插件,配置各種環境變量,

今天我的實驗環境是

使用Jenkins 拉取gitlap上項目的代碼,然後自動編譯並發布到tomcat中。

配置Jenkins

1、這裏配置的就是你代碼所存放的位置,還有你的項目名稱和描述之類的

技術分享圖片

2、配置觸發器所需執行的一些東西,我這裏配置了一個定時檢測拉取的動作。

技術分享圖片

3、配置tomcta

技術分享圖片

這裏要註意,最好單獨創建一個賬號,並賦予相關權限

<!--
  <role rolename="tomcat"
/> <role rolename="role1"/> <user username="tomcat" password="<must-be-changed>" roles="tomcat"/> <user username="both" password="<must-be-changed>" roles="tomcat,role1"/> <user username="role1" password="<must-be-changed>" roles="role1"/> --> <!-- <role rolename="
admin"/> --> <!-- <role rolename="admin-gui"/> --> <!-- <role rolename="admin-script"/> --> <!-- <role rolename="manager"/> --> <!-- <role rolename="manager-gui"/> --> <!-- <role rolename="manager-script"/> --> <!-- <role rolename="
manager-jmx"/> --> <!-- <role rolename="manager-status"/> --> <user name="admin" password="adminadmin" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status" /> <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="upload" password="upload" roles="manager-gui,manager-script"/> </tomcat-users>

構建並查看日誌

點擊開始構建,然後查看輸出日誌結果,如果沒有報錯,大概就沒有啥問題,說下我這裏遇到的一個坑

技術分享圖片

查看了一下大概報錯原因,然後我將context關掉了,這個是否要求上下文路徑,這個要看代碼裏pom文件裏有沒有強制要求,如果沒有就不用寫,

然後我清除了一下工作目錄,自動部署成功日誌輸出也正常了,

解決問題鏈接地址:

https://blog.csdn.net/alanzyy/article/details/60596402

http://www.alanzeng.cn/2017/03/jenkins-random-failed-deploy-tomcat/

正確輸出

Started by user starry
Building in workspace /home/Jenkins-home/.jenkins/workspace/test-raymedy
Cloning the remote Git repository
remote: Counting objects
Receiving objects
Resolving deltas
Updating references
Checking out Revision 9ea6a0d4951c90b9c62cc9c03c4b3e575804e5ec (refs/remotes/origin/master)
Commit message: "Merge remote-tracking branch ‘origin/master‘"
Parsing POMs
Modules changed, recalculating dependency graph
Established TCP socket on 58075
[test-raymedy] $ /home/java/jdk1.8.0_65/bin/java -cp /home/Jenkins-home/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-agent-1.11.jar:/home/maven339/boot/plexus-classworlds-2.5.2.jar:/home/maven339/conf/logging jenkins.maven3.agent.Maven33Main /home/maven339 /home/apache-tomcat-jenkins/webapps/ROOT/WEB-INF/lib/remoting-3.7.jar /home/Jenkins-home/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-interceptor-1.11.jar /home/Jenkins-home/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.11.jar 58075
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f /home/Jenkins-home/.jenkins/workspace/test-raymedy/pom.xml install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building raymedy Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ raymedy ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 9 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ raymedy ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 114 source files to /home/Jenkins-home/.jenkins/workspace/test-raymedy/target/classes
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/FileTool.java:[11,16] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[5,16] sun.misc.BASE64Decoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[6,16] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/FileTool.java:[11,16] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[5,16] sun.misc.BASE64Decoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[6,16] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/FileTool.java:[11,16] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[5,16] sun.misc.BASE64Decoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[6,16] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/FileTool.java:[11,16] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[5,16] sun.misc.BASE64Decoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[6,16] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/FileTool.java:[389,26] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[38,20] sun.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/AESEncryptTool.java:[54,37] sun.misc.BASE64Decoder is internal proprietary API and may be removed in a future release
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/Message/SMSUtil.java: /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/Message/SMSUtil.java uses or overrides a deprecated API.
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Tools/Message/SMSUtil.java: Recompile with -Xlint:deprecation for details.
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Resources/BasicService.java: Some input files use unchecked or unsafe operations.
[WARNING] /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/com/topsci/Resources/BasicService.java: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ raymedy ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/Jenkins-home/.jenkins/workspace/test-raymedy/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ raymedy ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ raymedy ---
[INFO] No tests to run.
[JENKINS] Recording test results
[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ raymedy ---
[INFO] Packaging webapp
[INFO] Assembling webapp [raymedy] in [/home/Jenkins-home/.jenkins/workspace/test-raymedy/target/raymedy]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/Jenkins-home/.jenkins/workspace/test-raymedy/WebContent]
[INFO] Webapp assembled in [122 msecs]
[INFO] Building war: /home/Jenkins-home/.jenkins/workspace/test-raymedy/target/raymedy.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ raymedy ---
[INFO] Installing /home/Jenkins-home/.jenkins/workspace/test-raymedy/target/raymedy.war to /root/.m2/repository/raymedy/raymedy/1.0-SNAPSHOT/raymedy-1.0-SNAPSHOT.war
[INFO] Installing /home/Jenkins-home/.jenkins/workspace/test-raymedy/pom.xml to /root/.m2/repository/raymedy/raymedy/1.0-SNAPSHOT/raymedy-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.680 s
[INFO] Finished at: 2019-01-13T10:48:17+08:00
[INFO] Final Memory: 36M/551M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving /home/Jenkins-home/.jenkins/workspace/test-raymedy/pom.xml to raymedy/raymedy/1.0-SNAPSHOT/raymedy-1.0-SNAPSHOT.pom
[JENKINS] Archiving /home/Jenkins-home/.jenkins/workspace/test-raymedy/target/raymedy.war to raymedy/raymedy/1.0-SNAPSHOT/raymedy-1.0-SNAPSHOT.war
channel stopped
Deploying /home/Jenkins-home/.jenkins/workspace/test-raymedy/target/raymedy.war to container Tomcat 7.x Remote with context 
  Redeploying [/home/Jenkins-home/.jenkins/workspace/test-raymedy/target/raymedy.war]
  Undeploying [/home/Jenkins-home/.jenkins/workspace/test-raymedy/target/raymedy.war]
  Deploying [/home/Jenkins-home/.jenkins/workspace/test-raymedy/target/raymedy.war]
Finished: SUCCESS

最終效果

技術分享圖片

不足之處還請大家指教,謝謝啦

Jenkins (自動化發布)