jenkins一键推送到远程服务器并用docker容器启动

embedded/2024/10/21 11:37:11/

jenkins_0">1.安装jenkins

我后端使用的是宝塔面板来安装的容器jenkins,要选中允许外部访问,安装完之后没有那个选项了,一开始安装的时候要选中不使用域名和后面的允许外部访问。Jenkins 版本为: 2.462.1
Jenkins版本

2.配置Jenkins

2.1 Git plugin

安装完毕之后可以在项目构建的之后直接从gitee中拉取代码,不过需要先配置全局凭证,我这边使用的是账户密码。

代码拉取

2.2Maven Integration plugin

安装完毕之后可以构建maven项目。
构建maven项目

2.3Publish Over SSH

安装之后可以将代码推送到远程服务器,首先保存全局凭证,此处我使用的还是账号密码,然后再system下配置Publish Over SSH。之后点击下方测试查看是否可以正常连接。
Publish Over SSH配置
然后在项目构建中,Post Steps下面添加生成后的步骤,"通过SSH发送文件或执行命令"选项, 然后添加如下配置:
步骤配置
服务器是上面配置的。
源文件:定义为:**/*,不过为了不必要的传输改为 **/ruoyi-admin.jar
删除前缀:是根据打包后文件所在路径来进行删除,不然会把目录也推送到远程服务器
远程目录:远程目录为空时,默认使用上面服务器配置的路径
Exec 命令:在远程服务器上执行的命令

3. 构建记录和访问结果

channel stopped
SSH: Connecting from host [d4ea9e4c162f]
SSH: Connecting with configuration [one day server] ...
SSH: Creating session: username [root], hostname [154.64.000.102], port [22]
SSH: Connecting session ...
SSH: Connected
SSH: Opening SFTP channel ...
SSH: SFTP channel open
SSH: Connecting SFTP channel ...
SSH: Connected
SSH: cd [/develop/ruoyi/]
SSH: OK
SSH: cd [/develop/ruoyi/]
SSH: OK
SSH: put [ruoyi-admin.jar]
SSH: Opening exec channel ...
SSH: EXEC: channel open
SSH: EXEC: STDOUT/STDERR from command [cd /develop/ruoyi/nohup java -jar ruoyi-admin.jar] ...
SSH: EXEC: connected
Application Version: 4.7.9
Spring Boot Version: 2.5.15//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.___\_____/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//             佛祖保佑       永不宕机      永无BUG               //11:32:16.142 [main] INFO  c.r.RuoYiApplication - [logStarting,55] - Starting RuoYiApplication using Java 1.8.0_362 on instance-6obVdquJ with PID 332642 (/develop/ruoyi/ruoyi-admin.jar started by root in /develop/ruoyi)
11:32:16.161 [main] DEBUG c.r.RuoYiApplication - [logStarting,56] - Running with Spring Boot v2.5.15, Spring v5.3.33
11:32:16.162 [main] INFO  c.r.RuoYiApplication - [logStartupProfileInfo,686] - The following 1 profile is active: "druid"
11:32:16.166 [background-preinit] INFO  o.h.v.i.util.Version - [<clinit>,21] - HV000001: Hibernate Validator 6.2.5.Final
11:32:19.002 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-authCache]
11:32:20.217 [main] INFO  c.a.d.p.DruidDataSource - [init,1002] - {dataSource-1} inited
11:32:21.523 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [loginRecordCache]
11:32:21.620 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,135] - ==>  Preparing: select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from sys_config
11:32:21.860 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,135] - ==> Parameters: 
11:32:21.894 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,135] - <==      Total: 11
11:32:21.901 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.906 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.907 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.907 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.908 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.909 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.909 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.910 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.911 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.912 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.912 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:22.539 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,135] - ==>  Preparing: select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark from sys_dict_data WHERE status = ?
11:32:22.550 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,135] - ==> Parameters: 0(String)
11:32:22.573 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,135] - <==      Total: 29
11:32:22.577 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.579 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.579 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.580 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.581 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.582 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.582 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.583 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.583 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.585 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.851 [main] INFO  o.q.i.StdSchedulerFactory - [instantiate,1220] - Using default implementation for ThreadExecutor
11:32:22.878 [main] INFO  o.q.c.SchedulerSignalerImpl - [<init>,61] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
11:32:22.879 [main] INFO  o.q.c.QuartzScheduler - [<init>,229] - Quartz Scheduler v.2.3.2 created.
11:32:22.880 [main] INFO  o.q.s.RAMJobStore - [initialize,155] - RAMJobStore initialized.
11:32:22.881 [main] INFO  o.q.c.QuartzScheduler - [initialize,294] - Scheduler meta-data: Quartz Scheduler (v2.3.2) 'quartzScheduler' with instanceId 'NON_CLUSTERED'Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.NOT STARTED.Currently in standby mode.Number of jobs executed: 0Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.11:32:22.882 [main] INFO  o.q.i.StdSchedulerFactory - [instantiate,1374] - Quartz scheduler 'quartzScheduler' initialized from an externally provided properties instance.
11:32:22.882 [main] INFO  o.q.i.StdSchedulerFactory - [instantiate,1378] - Quartz scheduler version: 2.3.2
11:32:22.883 [main] INFO  o.q.c.QuartzScheduler - [setJobFactory,2293] - JobFactory set to: org.springframework.scheduling.quartz.SpringBeanJobFactory@14fc1f0
11:32:22.950 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,135] - ==>  Preparing: select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark from sys_job
11:32:22.952 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,135] - ==> Parameters: 
11:32:22.957 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,135] - <==      Total: 3
11:32:23.374 [main] INFO  o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-userCache]
11:32:23.704 [main] INFO  o.a.c.h.Http11NioProtocol - [log,173] - Initializing ProtocolHandler ["http-nio-80"]
11:32:23.704 [main] INFO  o.a.c.c.StandardService - [log,173] - Starting service [Tomcat]
11:32:23.705 [main] INFO  o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/9.0.75]
11:32:23.778 [main] INFO  o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext
11:32:26.083 [main] INFO  o.a.c.h.Http11NioProtocol - [log,173] - Starting ProtocolHandler ["http-nio-80"]
11:32:26.741 [main] INFO  o.q.c.QuartzScheduler - [start,547] - Scheduler quartzScheduler_$_NON_CLUSTERED started.
11:32:26.754 [main] INFO  c.r.RuoYiApplication - [logStarted,61] - Started RuoYiApplication in 11.293 seconds (JVM running for 12.178)
(♥◠‿◠)ノ゙  若依启动成功   ლ(´ڡ`)゙  .-------.       ____     __        |  _ _   \      \   \   /  /    | ( ' )  |       \  _. /  '       |(_ o _) /        _( )_ .'         | (_,_).' __  ___(_ o _)'          |  |\ \  |  ||   |(_,_)'         |  | \ `'   /|   `-'  /           |  |  \    /  \      /           ''-'   `'-'    `-..-'              

在这里插入图片描述

docker_145">4.使用docker启动项目

保证远程服务器已经安装docker,然后将下面的命令放到exce命令里面

# 打开文件发送到的路径
cd /develop/ruoyi/
# 停止容器ruoyi
docker stop ruoyi
# 删除容器ruoyi
docker rm ruoyi
# 删除标签为admin-image的镜像(应该是,需要测试)
docker rmi -f admin-image
# 根据dockerfile创建新的标签为admin-image的镜像。
# 后面的.代表执行dockerfile,dockerfile和ruoyi-admin.jar在同级目录下
docker build -t admin-image .
# 后台启动容器容器名称为ruoyi,对外暴露端口号80
# -d为后台启动
docker run -d --name ruoyi -p 80:80 admin-image

下面是dockerfile:

# 基础镜像
FROM  openjdk:8-jre
# 挂载目录
VOLUME /home/ruoyi
# 创建目录
RUN mkdir -p /home/ruoyi
# 指定路径
WORKDIR /home/ruoyi
# 设置时区为上海
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone
# 复制jar文件到路径
COPY ./ruoyi-admin.jar /home/ruoyi/ruoyi-admin.jar
# 启动系统服务
ENTRYPOINT ["java","-Xms125m","-Xmx125m","-jar","ruoyi-admin.jar"]

http://www.ppmy.cn/embedded/94621.html

相关文章

SpringCloud 微服务nacos和eureka

Spring是微服务架构&#xff0c;是一种经过良好架构设计的分布式架构方案。 微服务架构有如下特性 单一&#xff1a;微服务拆分粒度小&#xff0c;每一个服务都对应唯一的业务能力&#xff0c;做到单一职责&#xff0c;避免重复业务开发 面向服务&#xff1a;微服务对外暴漏…

CC攻击解决方案,如何处理CC攻击

在数字化时代&#xff0c;网站作为企业与用户交流的重要窗口&#xff0c;其安全性和稳定性至关重要。然而&#xff0c;CC攻击&#xff08;Challenge Collapsar Attack&#xff09;这一网络威胁如同网络世界中的“洪水猛兽”&#xff0c;时刻威胁着网站的正常运行。今天我们就来…

仲阳天王星运维实习一面

自我介绍&#xff1f; 略谈谈你对“仲阳天王星”的理解&#xff1f; 略实习时间怎么安排&#xff0c;后续时间是怎么规划的&#xff1f; 略给你一个装满水的8升满壶和两个分别是5升、3升的空壶&#xff0c;请想个办法&#xff0c;使得其中一个水壶恰好装4升水&#xff0c;每一步…

无字母数字_$ webshell之命令执行

题解分析&#xff1a; 代码案例 当然&#xff0c;这道题的限制&#xff1a; webshell长度不超过35位 不包含字母数字&#xff0c;还不能包含$和_ 所以&#xff0c;如何解决这个问题&#xff1f; shell下可以利用.来执行任意脚本 Linux文件名支持用glob通配符代替 第一点.…

网关与AWS云心跳周期,网关断电或者网络不稳定的离线机制

当mqtt连线建立时, 需要指定keep alive参数,当 iot core在1.5倍 keep alive timeout时长内都没收到任何来自设备端的操作, 例如 ping, subscribe, publish &#xff0c;则会主动将连线中断。如果iot core检测到tcp 连接中断, 会立即中断&#xff1b;如果未检测到则会等到1.5倍 …

微信小程序 checkbox 实现双向绑定以及特殊交互处理

wxml文件代码如下&#xff1a; <!--页面顶部 引入wxs文件--> <wxs module"tools" src"../../filter/tools.wxs"></wxs> ... <checkbox-group bindchange"checkboxChange"><label class"weui-cell weui-check__…

【机器学习基础】线性回归

【作者主页】Francek Chen 【专栏介绍】 ⌈ ⌈ ⌈Python机器学习 ⌋ ⌋ ⌋ 机器学习是一门人工智能的分支学科&#xff0c;通过算法和模型让计算机从数据中学习&#xff0c;进行模型训练和优化&#xff0c;做出预测、分类和决策支持。Python成为机器学习的首选语言&#xff0c;…

Java毕业设计 基于SSM和Vue的酒店管理系统小程序

Java毕业设计 基于SSM和Vue的酒店管理系统小程序 这篇博文将介绍一个基于SSM框架和Vue开发的酒店管理系统微信小程序&#xff0c;适合用于Java毕业设计。 功能介绍 用户 登录 注册 忘记密码 首页 图片轮播 房间信息 房间详情 预订 收藏 评论 我的 订单信息 酒店管理…