1、持续集成javaweb

首先咱们需要安装一个 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

最终效果

2、持续集成nodejs

nodejs相比java还要简单一些,Jenkins完成构建发送发布服务器直接执行就ok了

1、第一步跟java的一样,设置项目的一些必要参数,以及你的项目的git的地址

2、选择你构建的环境,前提是你要装好nodejs,和Jenkins对nodejs支持的一下插件

我这里做的就是在Jenkins的目录下将项目安装并打包。

3、推送到发布服务器,执行相应命令,来运行你的项目

这里如果比较简单的命令可以直接在  Exec command 里面填写,但是如果过多最好还是已脚本的形式,一个是便于修改,还有就是便于测试。

要记住一点就是,这个没有自动更新的功能,所以要设置,关闭老项目,清理旧的文件或者备份,并启动新的项目

脚本

我这里没有写日志,如果发生错误了,不便于排查,最好可以将脚本的执行结果打印到某一文件中方便查询排错。

#!/bin/bash
cd /home
killall node
rm -rf /home/protct/
unzip healthy_protect_server.zip -d /home/protct/
rm -rf /home/healthy_protect_server.zip
setsid /usr/local/src/node-v8.9.1-linux-x64/bin/node /home/protct/bin/healthy_protect_server &
touch /okle
exit 0

Jenkins (1、自动化发布war包、2、自动化发布nodejs)的更多相关文章

  1. 推荐几位jenkins发布war包和jar包大佬的博客

    jenkins部署tomcat的war包和jar包 https://blog.csdn.net/liuxiaoming1109/article/details/89311696  

  2. Liferay 6.2 改造系列之二十二:如何发布WAR包

    1.修改web资源并发布 如果修改了默认主题信息,需执行portal-web中的build-themes任务: 执行portal-web中的deploy任务: 2.修改portal-impl中的jav ...

  3. 使用Tomcat发布war包

    第一步:下载tomacat 1.下载地址:http://tomcat.apache.org 2.解压后目录如下 3.双击bin文件夹下startup.bat 即可启动tomcat, 计算机会弹出控制台 ...

  4. Spring Boot发布war包流程

    1.修改web model的pom.xml <packaging>war</packaging> SpringBoot默认发布的都是jar,因此要修改默认的打包方式jar为wa ...

  5. Hudson管理平台自动化部署war包

    继上一篇:Hudson持续集成管理平台搭建 后,我们需要进行项目的自动化部署. 首先:我们先配置<系统管理>中的[系统设置] 然后返回到首页,点击项目名称进入项目内,点击设置: 翻到最底下 ...

  6. jenkins发布.war包到本地tomcat

    前提:保证jenkins构建打包成功 1.配置tomcat的用户名密码(此处tomcat为本地任意tomcat包,jenkins会通过Deploy war/ear to container配置的url ...

  7. jenkins+svn+tomcat部署war包

    svn是版本控制器,是提供一个版本库让程序员把项目提交上去,每一次更新代码提交后都会记录 jenkins是持续部署的工具,是让项目自动部署发布出去的工具,当项目代码发生改变时就需要重新打包成war包, ...

  8. Tomcat自动发布war包

    有两种方法: 1.将项目打成war包,复制到${tomcat.home}\webapps目录下.当tomcat启动时会自动将其解包. 有人说,不能直接将war文件夹直接复制到${tomcat.home ...

  9. linux下springboot项目通过jetty发布war包应用

    Linux下jetty发布jar包 1.通过官网下载jetty点击下载https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distributi ...

  10. resin4 发布war包

    1.将web项目打包成xxxx.war 2.将war包放到webapps下 3.修改conf/resin.xml文件如下部分: <!-- - Configures the main applic ...

随机推荐

  1. 为什么import React from 'react',React首字母必须大写?

    很奇怪的是,明明没有用到 React,但是我不得不 import React.这是为什么? import React from 'react'; export default function (pr ...

  2. Codefroces 1328E Tree Querie(dfs序)

    Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距 ...

  3. Buffer的重要属性 position/limit/capacity

    1 package nio; 2 3 import java.nio.IntBuffer; 4 5 /** 6 * Buffer的重要属性 position/limit/capacity 7 * po ...

  4. 新建表后,在sqlserver manager中使用显示引用对象无效

    编辑>intelliSense(I)>刷新本地缓存.

  5. 2.2.1 Sqoop1的基本架构

    当用户通过shell命令提交迁移作业后,Sqoop会从关系型数据库中读取元信息,并根据并发度和数据表大小将数据划分成若干分片,每片交给一个Map Task处理,这样多个Map Task同时读取数据库中 ...

  6. 九、kafka伪分布式和集群搭建

    伪分布式: 1.先将zk启动,如果是在伪分布式下,kafka已经集成了zk nohup /kafka_2.11-0.10.0.1/bin/zookeeper-server-start.sh /kafk ...

  7. Nginx解决前端访问资源跨域问题

    被前端跨域问题折磨快2天后,终于用ngnx的方式解决了,所以在此总结下. 该篇只探讨如何用Ngnx解决跨域问题,对于原理不作讨论. 1.首先介绍Windows环境下Nignx的相关命令操作 nginx ...

  8. redis之集群一:主从

    Redis的三种集群模式 Redis有三种集群模式,第一个就是主从模式,第二种"哨兵"模式,第三种是Cluster集群模式,第三种的集群模式是在Redis 3.x以后的版本才增加进 ...

  9. 【Nginx】配置nginx图片服务器

    想通过nginx来访问服务器上的图片 可以搭建一个nginx图片服务器. 做法如下: 先安装nginx,这里直接用yum来进行安装的 安装方法如下: https://blog.csdn.net/iml ...

  10. Windows Server 2012 R2远程桌面默认端口修改

    修改3389默认端口可使服务器安全性进一步提升,可以避免阻断大部分的恶意暴力密码爆破. 在开始--运行菜单里,输入regedit 或者: 远程登陆服务器选择系统桌面中的"Windows Po ...