服务器版本

Linux version 3.10.0-957.12.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Mon Apr 29 14:59:59 UTC 2019

准备 :

Jenkins 官网 : https://jenkins.io

Jenkins执行安装

启动 Jenkins :

[root@hybn guns-logs]# service jenkins start/stop/restart
Usage: /etc/init.d/jenkins {start|stop|status|try-restart|restart|force-reload|reload|probe}
[root@hybn guns-logs]# chkconfig jenkins on

查看端口 :

[root@hybn guns-logs]# cat /etc/sysconfig/jenkins 

## Type:        integer(0:65535)
## Default: 8080
## ServiceRestart: jenkins
#
# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8080"

开放端口 :

[root@hybn guns-logs]# firewall-cmd --zone=public --add-port=8080/tcp --permanent

配置Java路径 :

[root@hybn guns-logs]# vim /etc/init.d/jenkins
-----------------S----------------------
candidates="
/hybn/package/jdk/jdk1.8.0_211/bin/java --添加Java路径
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/bin/java
"
-----------------E---------------------- [root@hybn init.d]# service jenkins start
Starting jenkins (via systemctl): Warning: jenkins.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[ OK ]

运行服务 :

[root@hybn jenkins]# firewall-cmd --zone=public --add-port=8080/tcp --permanent 

jenkins.war  nohup.out  start.sh

[root@hybn jenkins]#  firewall-cmd --zone=public --list-ports
3306/tcp 22/tcp 443/tcp 80/tcp 8080/tcp 1001/tcp [root@hybn jenkins]# service jenkins start
Starting jenkins (via systemctl): [ OK ]

浏览器打开:http:<ip>:<host>

在配置第一个管理员账户后会出现卡死,这时候重启jenkins服务即可 :

[root@hybn jenkins]# systemctl reload jenkins

配置构建环境 :

Post Steps 构建后执行Shell :

网上的看不懂,自己捣鼓了一个,能用。

#!/bin/bash

echo "===================开始部署ERP================"
pid=`pgrep -f erp.jar`
#判断进程
if [ -n "$pid" ];then
kill -9 $pid
fi #生成当前时间戳
date_dir="/hybn/jar/history/$(date +%y_%m_%d-%H:%M:%S)"
echo "$date_dir"
#创建历史文件夹 根据时间戳命名
mkdir "$date_dir"
#移动到历史记录
if [ ! -f "/hybn/jar/run/erp.jar" ];then
echo "jar不存在 直接部署"
mv /var/lib/jenkins/workspace/erp_web/target/erp.jar /hybn/jar/run
else
echo "jar存在 备份"
mv /hybn/jar/run/erp.jar $date_dir
mv /var/lib/jenkins/workspace/erp_web/target/erp.jar /hybn/jar/run
fi cd /hybn/jar/run #将生成的jar移动到项目目录 cd /hybn/jar/run ./start.sh echo "===================部署成功!================"

结果 :

0:31:38 Started by user 杨超杰
00:31:38 Building in workspace /var/lib/jenkins/workspace/erp_web
00:31:38 using credential b9b73622-ceb7-4d43-8ede-005f4d817712
00:31:38 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
00:31:38 Fetching changes from the remote Git repository
00:31:38 > /usr/bin/git config remote.origin.url https://gitee.com/huawin_bainer_information/erp.git # timeout=10
00:31:38 Fetching upstream changes from https://gitee.com/huawin_bainer_information/erp.git
00:31:38 > /usr/bin/git --version # timeout=10
00:31:38 using GIT_ASKPASS to set credentials
00:31:38 > /usr/bin/git fetch --tags --progress https://gitee.com/huawin_bainer_information/erp.git +refs/heads/*:refs/remotes/origin/*
00:31:39 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
00:31:39 > /usr/bin/git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
00:31:39 Checking out Revision d69a25f8c207ebad5dd6a7274322fd7f0878d091 (refs/remotes/origin/master)
00:31:39 > /usr/bin/git config core.sparsecheckout # timeout=10
00:31:39 > /usr/bin/git checkout -f d69a25f8c207ebad5dd6a7274322fd7f0878d091
00:31:39 Commit message: "Sql更新,账户Bug修复,费用中心选择账户,费用计算,新增费用记录表。"
00:31:39 > /usr/bin/git rev-list --no-walk d69a25f8c207ebad5dd6a7274322fd7f0878d091 # timeout=10
00:31:39 Parsing POMs
00:31:40 Established TCP socket on 34128
00:31:40 [erp_web] $ /hybn/package/jdk/jdk1.8.0_211//bin/java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-agent-1.12.jar:/usr/share/maven/boot/plexus-classworlds.jar org.jvnet.hudson.maven3.agent.Maven3Main /usr/share/maven /var/cache/jenkins/war/WEB-INF/lib/remoting-3.29.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-1.12.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.12.jar 34128
00:31:43 <===[JENKINS REMOTING CAPACITY]===>channel started
00:31:46 Executing Maven: -B -f /var/lib/jenkins/workspace/erp_web/pom.xml clean package -Dmaven.test.skip=true
00:31:48 [INFO] Scanning for projects...
00:31:49 [INFO]
00:31:49 [INFO] ------------------------------------------------------------------------
00:31:49 [INFO] Building guns-admin 1.0.0
00:31:49 [INFO] ------------------------------------------------------------------------
00:31:54 [INFO]
00:31:54 [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ erp ---
00:31:54 [INFO] Deleting /var/lib/jenkins/workspace/erp_web/target
00:31:55 [INFO]
00:31:55 [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ erp ---
00:31:55 [INFO] Using 'UTF-8' encoding to copy filtered resources.
00:31:55 [INFO] Copying 601 resources
00:31:55 [INFO] Copying 8 resources
00:31:56 [INFO] Copying 59 resources
00:31:56 [INFO]
00:31:56 [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ erp ---
00:31:57 [INFO] Changes detected - recompiling the module!
00:31:57 [INFO] Compiling 510 source files to /var/lib/jenkins/workspace/erp_web/target/classes
00:32:18 [WARNING] /var/lib/jenkins/workspace/erp_web/src/main/java/cn/hybn/erp/modular/system/service/impl/InventoryTransactionServiceImpl.java: Some input files use unchecked or unsafe operations.
00:32:18 [WARNING] /var/lib/jenkins/workspace/erp_web/src/main/java/cn/hybn/erp/modular/system/service/impl/InventoryTransactionServiceImpl.java: Recompile with -Xlint:unchecked for details.
00:32:19 [INFO]
00:32:19 [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ erp ---
00:32:19 [INFO] Not copying test resources
00:32:19 [INFO]
00:32:19 [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ erp ---
00:32:19 [INFO] Not compiling test sources
00:32:19 [INFO]
00:32:19 [INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ erp ---
00:32:19 [INFO] Tests are skipped.
00:32:20 [WARNING] Attempt to (de-)serialize anonymous class hudson.maven.reporters.BuildInfoRecorder$1; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
00:32:20 [INFO]
00:32:20 [INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ erp ---
00:32:20 [INFO] Building jar: /var/lib/jenkins/workspace/erp_web/target/erp.jar
00:32:21 [INFO]
00:32:21 [INFO] --- spring-boot-maven-plugin:2.1.1.RELEASE:repackage (repackage) @ erp ---
00:32:22 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
00:32:22 SLF4J: Defaulting to no-operation (NOP) logger implementation
00:32:22 SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
00:32:24 [INFO] Replacing main artifact with repackaged archive
00:32:24 [INFO]
00:32:24 [INFO] --- spring-boot-maven-plugin:2.1.1.RELEASE:repackage (default) @ erp ---
00:32:24 [INFO] Replacing main artifact with repackaged archive
00:32:25 [INFO] ------------------------------------------------------------------------
00:32:25 [INFO] BUILD SUCCESS
00:32:25 [INFO] ------------------------------------------------------------------------
00:32:25 [INFO] Total time: 37.107s
00:32:25 [INFO] Finished at: Thu May 16 00:32:25 CST 2019
00:32:26 [INFO] Final Memory: 66M/477M
00:32:26 [INFO] ------------------------------------------------------------------------
00:32:26 Waiting for Jenkins to finish collecting data
00:32:28 [JENKINS] Archiving /var/lib/jenkins/workspace/erp_web/pom.xml to cn.hybn/erp/1.0.0/erp-1.0.0.pom
00:32:28 [JENKINS] Archiving /var/lib/jenkins/workspace/erp_web/target/erp.jar to cn.hybn/erp/1.0.0/erp-1.0.0.jar
00:32:29 [erp_web] $ /bin/bash /tmp/jenkins1615489592064061878.sh
00:32:29 channel stopped
00:32:29 ===================开始部署ERP================
00:32:29 /tmp/jenkins1615489592064061878.sh: line 7: kill: (13629) - Operation not permitted
00:32:29 /hybn/jar/history/19_05_16-00:32:29
00:32:29 mkdir: cannot create directory ‘/hybn/jar/history/19_05_16-00:32:29’: Permission denied
00:32:29 jar存在 备份
00:32:29 mv: cannot move ‘/hybn/jar/run/erp.jar’ to ‘/hybn/jar/history/19_05_16-00:32:29’: Permission denied
00:32:29 mv: cannot move ‘/var/lib/jenkins/workspace/erp_web/target/erp.jar’ to ‘/hybn/jar/run/erp.jar’: Permission denied
00:32:29 ===================部署成功!================
00:32:34 2019-05-16 00:32:34.536 ERROR 14039 --- [ main] o.s.boot.SpringApplication : Application run failed

Jenkins Root 运行 :

[root@hybn tmp]# vim /etc/sysconfig/jenkins
JENKINS_USER="root"
[root@hybn tmp]# chown -R root:root /usr/lib/jenkins
[root@hybn tmp]# chown -R root:root /var/cache/jenkins
[root@hybn tmp]# chown -R root:root /var/log/jenkins
[root@hybn jenkins]# systemctl reload jenkins
[root@hybn jenkins]# ps -ef | grep jenkins
root 20115 1 99 13:13 ? 00:02:17 /hybn/package/jdk/jdk1.8.0_211/bin/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/libjenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
root 20295 20115 99 13:14 ? 00:00:30 /hybn/package/jdk/jdk1.8.0_211//bin/java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-agent-1.12.jar:/usr/share/maven/boot/plexus-classworlds.jar org.jvnet.hudson.maven3.agent.Maven3Main /usr/share/maven /var/cache/jenkins/war/WEB-INF/lib/remoting-3.29.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-1.12.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.12.jar 41182
root 20452 19582 0 13:14 pts/0 00:00:00 grep --color=auto jenkins

DontKillME :

#!/bin/bash

echo "===================开始部署ERP================"
pid=`pgrep -f erp.jar`
#判断进程
if [ -n "$pid" ];then
kill -9 $pid
fi #生成当前时间戳
date_dir="/hybn/jar/history/$(date +%y_%m_%d-%H:%M:%S)"
echo "$date_dir"
#创建历史文件夹 mkdir "$date_dir"
#移动到历史记录
if [ ! -f "/hybn/jar/run/erp.jar" ];then
echo "jar不存在 直接部署"
mv /var/lib/jenkins/workspace/erp_web/target/erp.jar /hybn/jar/run
else
echo "jar存在 备份"
mv /hybn/jar/run/erp.jar $date_dir
mv /var/lib/jenkins/workspace/erp_web/target/erp.jar /hybn/jar/run
fi cd /hybn/jar/run #将生成的jar移动到项目目录 #启动 project_path=/hybn/jar/run
cd $project_path BUILD_ID=dontKillMe nohup java -Dfile.encoding=UTF-8 -jar erp.jar --spring.profiles.active=dev --server.port=8089 2>&1 & dpid=`pgrep -f erp.jar`
echo "PID----------$dpid------------------"
echo "===================部署成功!================"

Jenkins 配置 SpringBoot 自动构建部署的更多相关文章

  1. jenkins使用deploy-plugin自动构建部署war包

    jenkins+ant+maven+tomcat 1安装 jenkins 使用yum安装的 # 下载库 wget -O /etc/yum.repos.d/jenkins.repo http://pkg ...

  2. 使用Docker+Jenkins自动构建部署

    环境 Windows 10 Docker Version 18.06.1-ce-win73 (19507) 运行jenkins 运行jenkins 容器 docker run -d --name ln ...

  3. Linux下Jenkins与GitHub自动构建NetCore与部署

    今天我们来谈谈NetCore在Linux底下的持续集成与部署.NetCore我就不多介绍了,持续集成用的是Jenkins,源代码管理器用的是GitHub.我们就跟着博文往下走吧. 1.Linux环境 ...

  4. Ant + Jenkies +Tomcat 自动构建部署Web项目

    前言:博主资历尚浅,很多东西都还在刚起步学习的阶段,这几天开发任务比较轻,就在自己window系统下,模拟部署远程服务器,利用Jenkies + Ant + Tomcat 搭建了一个自动发布部署的环境 ...

  5. 解放双手 | Jenkins + gitlab + maven 自动打包部署项目

    前言 记录 Jenkins + gitlab + maven 自动打包部署后端项目详细过程! 需求背景 不会偷懒的程序员不是好码农,传统的项目部署,有时候采用本地手动打包,再通过ssh传到服务器部署运 ...

  6. Linux下Jenkins与GitHub自动构建Node项目(Vue)

    根据上篇文章<Linux下Jenkins与GitHub自动构建NetCore与部署>,我们知道了Jenkins的强大功能,自动构建,部署了一个NetCore的Web,让开发人员专注于开发, ...

  7. 使用jenkins进行项目的自动构建部署

    jenkins 简介 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括:持续的软件版本发布/测试项目和监控外部调用执行的工作. 官网地址地址: https://je ...

  8. 【转】使用Docker+Jenkins自动构建部署

    转载自 https://segmentfault.com/a/1190000012921606 环境 阿里云ESC,宿主机服务器安装Docker,在安全规则中确认8080端口开启. 客户端mac 运行 ...

  9. 使用jekins自动构建部署java maven项目(jdk1.7+tomcat7.0+jenkins2.19.3)

    1.下载jenkins 地址:https://jenkins.io/index.html 本人下载了2.19.3版本的war包:jenkins.war 2.安装jenkins 拷贝jenkins.wa ...

随机推荐

  1. CentOS 7出现Failed to start firewalld.service: Unit is masked的解决办法和firewalld 防火墙开关

    说明:刚刚使用systemctl start firewalld命令开启防火墙的时候,却开不成功,出现Failed to start firewalld.service: Unit is masked ...

  2. 解读TIME_WAIT--你在网上看到的大多数帖子可能都是错误的

    由于TCP协议整个机制也非常复杂我只能尽可能的在某一条线上来说,不可能面面俱到,如果有疏漏或者对于内容有异议可以留言.谢谢大家. 查看服务器上各个状态的统计数量: netstat -ant | awk ...

  3. 跟我学SpringCloud | 第八篇:Spring Cloud Bus 消息总线

    SpringCloud系列教程 | 第八篇:Spring Cloud Bus 消息总线 Springboot: 2.1.6.RELEASE SpringCloud: Greenwich.SR1 如无特 ...

  4. Ural 2062:Ambitious Experiment(树状数组 || 分块)

    http://acm.timus.ru/problem.aspx?space=1&num=2062 题意:有n个数,有一个值,q个询问,有单点询问操作,也有对于区间[l,r]的每个数i,使得n ...

  5. python的简介与简单使用

    简介: python的诞生 创始人:Guido van Rossum(荷兰人:吉多) 时间:1989年 特点: 1.简单明了,容易上手 2.多平台,`全面发展,平衡发展, 3.胶水语言,有大量的库 其 ...

  6. Python Day_1

    听说Python很6,然后我的偶像小甲鱼竟然在6年前(现在2019年)就开始制作Python的教程,而前不久(世界读书日前一个星期左右),京东有活动,小甲鱼的Python第一版本打折,顺便买了本(还凑 ...

  7. Leetcode 195 Tenth Line

    Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...

  8. @ApiImplicitParam注解

    @Api:用在请求的类上,表示对类的说明 tags="说明该类的作用,可以在UI界面上看到的注解" value="该参数没什么意义,在UI界面上也看到,所以不需要配置&q ...

  9. .Net Core 使用百度UEditor编辑器

    一.准备文件 1. 下载UEditor官方版本.删除其中后端文件.保留后端文件夹中的config.json文件 2. 在NuGet管理器中搜索UEditorNetCore,拿到项目地址,下载源码 下载 ...

  10. Java底层技术系列文章-总揽

    对于工作中经常用到的东西,还是多看看实现原理,这样用着才能放心. 源码思想学习计划: 1.java基础库  HashCode深入理解 java线程框架窥探 2.集合类     java枚举类使用 递归 ...