打赏
Fork me on GitHub

[原]Jenkins(七)---jenkins项目编译测试发布由maven构建的web项目

/**

* lihaibo

* 文章内容都是根据自己工作情况实践得出。

* 版权声明:本博客欢迎转发,但请保留原作者信息!

http://www.cnblogs.com/horizonli/p/5332645.html

*/

一、使用maven编译

(maven编译  与 测试 test 和打包 package 和 部署 install 类似,不再赘述 )

在项目的配置页面中有个maven配置:里面只有一个clean   就是清除以前的构建信息:

之前我使用了clean   package来编译打包:结果如下图:

 

--------------------------------------------------------

当执行完只有clean的时候,之前构建的信息就被删除了:如下图

------------------------------------------------------

附注解:

/opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target


/opt/jenkins_tomcat6     表示jenkins工作目录

jobs/quick4j_demo        表示jenkins管理quick4j_demo项目的目录

workspace                表示maven等插件的工作目录

--------------------------------------------------------------------------------------------------

jenkins项目中使用maven扩展

这里的Goals  就是用maven 编译要用的命令如下图中所示:

jenkins使用maven编译以invoke top-level Maven targets中的Goals为准:

 
---------------------------------------------------------------------------------------------

二、部署到远程主机的tomcat中

     重点:两台机器要ssh远程root无密码登录。

     再回到Jenkins(二)---jenkins之Git+maven+jdk+tomcat中的全局图:

server A --->   jenkins主机ip:192.168.100.119

server B --->  远程部署主机IP:192.168.100.118

  

下面是编译过程日志

紫色字体jenkins使用git从gitlab仓库http://192.168.100.200/clq/quick4j.git拉取代码

黑色字体:jenkins使用maven编译测试发布web工程到本地 /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/quick4j.war

蓝色字体:jenkins使用ssh将本地打包好的war包传送到远程服务器的/opt/jenkins中

红色字体:jenkins远程执行远程服务器上的脚本,检查tomcat是否开启,如状态为开启,则关闭后,删除tomcat中原来的web项目包,再从/opt/jenkins中

              拷贝刚打包好的web项目war包到tomcat中,启动tomcat。

Started by user admin
Building in workspace /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace           #jenkins本机的工作目录
 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url http://192.168.100.200/clq/quick4j.git # timeout=10
Fetching upstream changes from http://192.168.100.200/clq/quick4j.git
 > /usr/bin/git --version # timeout=10
using .gitcredentials to set credentials
 > /usr/bin/git config --local credential.username clq # timeout=10
 > /usr/bin/git config --local credential.helper store --file=/opt/tomcat6/apache-tomcat-6.0.45/temp/git4880643529884290174.credentials # timeout=10
 > /usr/bin/git -c core.askpass=true fetch --tags --progress http://192.168.100.200/clq/quick4j.git +refs/heads/*:refs/remotes/origin/*
 > /usr/bin/git config --local --remove-section credential # timeout=10
 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > /usr/bin/git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision b123b099e8e72d7e467ab780ae28726a1c866797 (refs/remotes/origin/master)
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f b123b099e8e72d7e467ab780ae28726a1c866797
 > /usr/bin/git rev-list b123b099e8e72d7e467ab780ae28726a1c866797 # timeout=10
[workspace] $ /opt/apache-maven-3.3.9/bin/mvn -Dmaven.repo.local=/opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/.repository clean
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building quick4j App 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ quick4j ---
[INFO] Deleting /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.299 s
[INFO] Finished at: 2016-03-29T13:18:06+08:00
[INFO] Final Memory: 7M/238M
[INFO] ------------------------------------------------------------------------
[workspace] $ /bin/sh -xe /opt/tomcat6/apache-tomcat-6.0.45/temp/hudson1223364716445353332.sh
Parsing POMs
[workspace] $ /opt/JDK/bin/java -cp /opt/jenkins_tomcat6/plugins/maven-plugin/WEB-INF/lib/maven31-agent-1.5.jar:/opt/apache-maven-3.3.9
/boot/plexus-classworlds-2.5.2.jar:/opt/apache-maven-3.3.9/conf/logging jenkins.maven3.agent.Maven31Main
/opt/apache-maven-3.3.9 /opt/tomcat6/apache-tomcat-6.0.45/webapps/jenkins/WEB-INF/lib/remoting-2.51.jar
/opt/jenkins_tomcat6/plugins/maven-plugin/WEB-INF/lib/maven31-interceptor-1.5.jar
/opt/jenkins_tomcat6/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.5.jar 36966 <===[JENKINS REMOTING CAPACITY]===>channel started Executing Maven: -B -f /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/pom.xml
-Dmaven.repo.local=/opt/jenkins_tomcat6/maven-repositories/1 -s /opt/apache-maven-3.3.9/conf/settings.xml
-gs /opt/apache-maven-3.3.9/conf/settings.xml clean package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building quick4j App 1.0.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ quick4j --- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ quick4j --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 9 resources [INFO] Copying 3 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ quick4j --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 62 source files to /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ quick4j --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 3 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ quick4j --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 5 source files to /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/test-classes [INFO] [INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ quick4j --- [INFO] Tests are skipped. [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ quick4j --- [INFO] Packaging webapp [INFO] Assembling webapp [quick4j] in [/opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/quick4j] [INFO] Processing war project [INFO] Copying webapp resources [/opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/src/main/webapp] [INFO] Webapp assembled in [383 msecs] [INFO] Building war: /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/quick4j.war #发布构建好的web工程到本机工作目录下 [INFO] WEB-INF/web.xml already added, skipping [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.611 s [INFO] Finished at: 2016-03-29T13:18:15+08:00 [INFO] Final Memory: 28M/
438M [INFO] ------------------------------------------------------------------------ [JENKINS] Archiving /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/pom.xml to com.eliteams/quick4j/1.0.0/quick4j-1.0.0.pom [JENKINS] Archiving /opt/jenkins_tomcat6/jobs/quick4j_demo/workspace/target/quick4j.war to com.eliteams/quick4j/1.0.0/quick4j-1.0.0.war SSH: Connecting from host [Local-Machine-1] SSH: Connecting with configuration [192.168.100.118-ssh] ... SSH: Creating session: username [root], hostname [192.168.100.118], port [22] SSH: Connecting session ... channel stopped SSH: Connected SSH: Opening SFTP channel ... SSH: SFTP channel open SSH: Connecting SFTP channel ... SSH: Connected SSH: cd [/opt/jenkins] SSH: OK SSH: cd [/opt/jenkins] SSH: OK SSH: put [quick4j.war] SSH: OK SSH: Opening exec channel ... SSH: EXEC: channel open SSH: EXEC: STDOUT/STDERR from command [sh /opt/auto_deploy.sh] ... SSH: EXEC: connected ********************************** [2016-03-29]13:18:23 ************************************* updating server environment start updating server environment end check tomcat status... tomcat is running....port is 9090 shutdown tomcat..... >>>>>>>shutdown tomcat begin<<<<<<<< Using CATALINA_BASE: /opt/tomcat6/apache-tomcat-6.0.45 Using CATALINA_HOME: /opt/tomcat6/apache-tomcat-6.0.45 Using CATALINA_TMPDIR: /opt/tomcat6/apache-tomcat-6.0.45/temp Using JRE_HOME: /app/java/jdk1.8.0_11/jre Using CLASSPATH: /opt/tomcat6/apache-tomcat-6.0.45/bin/bootstrap.jar >>>>>>>shutdown tomcat end <<<<<<<< -------------- begin transfer war package to tomcat webapps ------------------- Find /opt/jenkins exist war package quick4j.war deleteing old package quick4j.war in /opt/tomcat6/apache-tomcat-6.0.45/webapps/ start transfer quick4j.war to /opt/tomcat6/apache-tomcat-6.0.45/webapps/ -------------- transfer war package to tomcat webapps end ------------------- >>>>>>> rebooting tomcat begin <<<<<<<< Using CATALINA_BASE: /opt/tomcat6/apache-tomcat-6.0.45 Using CATALINA_HOME: /opt/tomcat6/apache-tomcat-6.0.45 Using CATALINA_TMPDIR: /opt/tomcat6/apache-tomcat-6.0.45/temp Using JRE_HOME: /app/java/jdk1.8.0_11/jre Using CLASSPATH: /opt/tomcat6/apache-tomcat-6.0.45/bin/bootstrap.jar >>>>>>> rebooting tomcat end <<<<<<<< the log you can read in canalina.out ************************ deploy war package into container Successlly ********************************** SSH: EXEC: completed after 11,406 ms SSH: Disconnecting configuration [192.168.100.118-ssh] ... SSH: Transferred 1 file(s) Finished: SUCCESS

--------------------------------------------------------------------------------------------------------------------------------------------------------

三、浏览器验证是否正确发布:

jenkins主机ip:192.168.100.119

远程部署主机IP:192.168.100.118

发布成功

 

 --------------------目录电梯---------------------

[原]Jenkins(一)---我理解的jenkins是这样的

[原]Jenkins(二)---jenkins之Git+maven+jdk+tomcat

[原]Jenkins(三)---Jenkins初始配置和插件配置

[原]Jenkins(四)---Jenkins添加密钥对

[原]jenkins(五)---jenkins添加项目

[原]jenkins(六)---jenkins远程部署脚本

[原]Jenkins(七)---jenkins项目编译测试发布由maven构建的web项目

[原]Jenkins(八)---jenkins构建项目报错时发送错误报告邮件

[原]Jenkins(九)---jenkins分别发布多个项目到多个远程主机

[原]Jenkins(十)---jenkins注册管理员admin并赋所有权限给admin

[原]Jenkins(十一)---jenkins使用管理员admin创建用户和分配权限

[原]Jenkins(十二)---jenkins管理员用户无法登陆解决办法Access Denied

[原]Jenkins(十三)---jenkins用户权限管理

[原]Jenkins(十四)---jenkins示例:admin管理所有项目,新建用户只能看部分项目

[原]Jenkins(十五)---jenkins插件之deploy

posted @ 2016-03-29 13:38  my_cool2007  阅读(5417)  评论(1编辑  收藏  举报