Jenkins (1、自动化发布war包、2、自动化发布nodejs)
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)的更多相关文章
- 推荐几位jenkins发布war包和jar包大佬的博客
jenkins部署tomcat的war包和jar包 https://blog.csdn.net/liuxiaoming1109/article/details/89311696
- Liferay 6.2 改造系列之二十二:如何发布WAR包
1.修改web资源并发布 如果修改了默认主题信息,需执行portal-web中的build-themes任务: 执行portal-web中的deploy任务: 2.修改portal-impl中的jav ...
- 使用Tomcat发布war包
第一步:下载tomacat 1.下载地址:http://tomcat.apache.org 2.解压后目录如下 3.双击bin文件夹下startup.bat 即可启动tomcat, 计算机会弹出控制台 ...
- Spring Boot发布war包流程
1.修改web model的pom.xml <packaging>war</packaging> SpringBoot默认发布的都是jar,因此要修改默认的打包方式jar为wa ...
- Hudson管理平台自动化部署war包
继上一篇:Hudson持续集成管理平台搭建 后,我们需要进行项目的自动化部署. 首先:我们先配置<系统管理>中的[系统设置] 然后返回到首页,点击项目名称进入项目内,点击设置: 翻到最底下 ...
- jenkins发布.war包到本地tomcat
前提:保证jenkins构建打包成功 1.配置tomcat的用户名密码(此处tomcat为本地任意tomcat包,jenkins会通过Deploy war/ear to container配置的url ...
- jenkins+svn+tomcat部署war包
svn是版本控制器,是提供一个版本库让程序员把项目提交上去,每一次更新代码提交后都会记录 jenkins是持续部署的工具,是让项目自动部署发布出去的工具,当项目代码发生改变时就需要重新打包成war包, ...
- Tomcat自动发布war包
有两种方法: 1.将项目打成war包,复制到${tomcat.home}\webapps目录下.当tomcat启动时会自动将其解包. 有人说,不能直接将war文件夹直接复制到${tomcat.home ...
- linux下springboot项目通过jetty发布war包应用
Linux下jetty发布jar包 1.通过官网下载jetty点击下载https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distributi ...
- resin4 发布war包
1.将web项目打包成xxxx.war 2.将war包放到webapps下 3.修改conf/resin.xml文件如下部分: <!-- - Configures the main applic ...
随机推荐
- spring之ApplicationEvent 事件驱动
什么是ApplicationContext? 它是Spring的核心,Context我们通常解释为上下文环境,但是理解成容器会更好些. ApplicationContext则是应用的容器. Sprin ...
- GitHub基础使用指南
引言: 只要进行了一段时间的软件或者编程相关知识的学习,相信大家或多或少都会见过这只"猫猫",这可不是什么宠物店铺的商标,身为即将成为程序猿/媛的你,或者已经是一位程序猿/媛的你, ...
- java.io.NotSerializableException: org.apache.kafka.clients.consumer.ConsumerRecord
kafka 与spark集成 序列化问题 sparkConf.set("spark.serializer", "org.apache.spark.serializer.K ...
- 一个简单的字符串,为什么 Redis 要设计的如此特别
Redis 的 9 种数据类型 本文GitHub已收录:https://zhouwenxing.github.io/ Redis 中支持的数据类型到 5.0.5 版本,一共有 9 种.分别是: 1.B ...
- WPF Line 的颜色过度动画
<Line Grid.Column="2" Grid.ColumnSpan="2" VerticalAlignment="Center" ...
- LeetCode747 至少是其他数字两倍的最大数
在一个给定的数组nums中,总是存在一个最大元素 . 查找数组中的最大元素是否至少是数组中每个其他数字的两倍. 如果是,则返回最大元素的索引,否则返回-1. 示例 1: 输入: nums = [3, ...
- 一文搞懂MySQL前缀索引
引入 通常在开发中我们需要定义字符串类型的字段,例如用户名或者用户邮箱等. 假设我们在维护一个用户登录系统,用户表的定义: create table User( ID bigint unsigned ...
- LeetCode349. 两个数组的交集
题目 给定两个数组,编写一个函数来计算它们的交集. 分析 数组元素值可以很大,所以不适合直接开数组进行哈希,这里要学习另一种哈希方式:集合 集合有三种,区别见下面代码随想录的Carl大佬的表格,总结的 ...
- ctfhub技能树—web前置技能—http协议—Cookie
打开靶机环境 查看显示内容 根据提示,需要admin登录才能得到flag 题目介绍为Cookie欺骗.认证.伪造 介绍一下cookie和session 一.cookie: 在网站中,http请求是无状 ...
- ObjectMapper将josn字符串转化为List
一.利用ObjectMapper将json字符串转为List Student.java package objectmapper; import java.io.Serializable; publi ...