记录一次较为完整的Jenkins发布流程

文章目录

    • [1. Jenkins安装](#1. Jenkins安装)
      • [1.1 Jenkins Docker安装](#1.1 Jenkins Docker安装)
      • [1.2 Jenkins apt-get install安装](#1.2 Jenkins apt-get install安装)
    • [2. 关联github/gitee服务与webhook](#2. 关联github/gitee服务与webhook)
      • [2.1 配置ssh](#2.1 配置ssh)
      • [2.2 Jenkins关联](#2.2 Jenkins关联)
      • [2.3 WebHook](#2.3 WebHook)
    • [3. 前后端关联发布](#3. 前后端关联发布)

1. Jenkins安装

1.1 Jenkins Docker安装

Docker很好,但是我没有玩明白如何使用Docker的jenkins发布服务。因此仅做个记录

参考https://juejin.cn/post/7219899306946199610

这篇文章详细讲述了Docker中Jenkins如果想启其他docker服务的过程,值得参考
参考https://blog.csdn.net/BThinker/article/details/124178670

这篇文章详细讲述了Jenkins Docker的安装过程,值得参考

1.2 Jenkins apt-get install安装

直接参考官网https://pkg.jenkins.io/debian-stable/

This is the Debian package repository of Jenkins to automate installation and upgrade. To use this repository, first add the key to your system (for the Weekly Release Line):

复制代码
  sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
    https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

Then add a Jenkins apt repository entry:

复制代码
  echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
    https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
    /etc/apt/sources.list.d/jenkins.list > /dev/null

Update your local package index, then finally install Jenkins:

复制代码
sudo apt-get update
sudo apt-get install fontconfig openjdk-17-jre
sudo apt-get install jenkins

上述过程执行完毕,最终以systemctl的方式启动

如果要修改端口号,参考https://blog.csdn.net/Lifereunion/article/details/123430619

需要用systemctl status jenkins找到配置文件,然后直接在配置文件修改

借用评论区老哥的一句话

把配置写在服务里,这就离谱。。。估计都是用Jenkins源下载的吧,官方打包的人脑子有吭,如果直接安装rpm包就不会这样。

2. 关联github/gitee服务与webhook

参考 https://www.jianshu.com/p/dca1ec8187aa。写得很好

2.1 配置ssh

gitee和github流程差不多,都是本地

复制代码
ssh-keygen -t rsa -C "your_email@example.com"

2.2 Jenkins关联

生成的id_rsa.pub放到github的配置中

生成的id_rsa放到Jenkins中

2.3 WebHook

首先去System配置关联

这里的需要配置API令牌,记得自己存一份,以后就看不到这个API令牌了

在流水线中选择Generic Webhook Trigger

这里通过该网站https://chahuo.com/token-generator.html随机生成一段token

按照上述url在gitee部分也进行同样设置

3. 前后端关联发布

参考https://www.cnblogs.com/gaojinshun/p/15273011.html

我用的是shell的方式发布服务

注意一定需要加入BUILD_ID=dontKillMe,否则jenkins默认会在构建完成后杀掉构建过程中又jenkins中shell命令触发的衍生进程。

复制代码
BUILD_ID=dontKillMe

pwd
ls -lr
sh ./kill5050.sh

npm install
npm install forever -g
forever start server.js
相关推荐
RisunJan1 小时前
Linux命令-scriptreplay(终端会话回放)
linux·运维·chrome
x²+(y-√³x²)²=12 小时前
Linux打包文件到Windows,文件/文件类型丢失
linux·运维·windows
世人万千丶3 小时前
去重插入与超限淘汰:ArkTS 实现鸿蒙搜索历史的 LIMIT 艺术
运维·服务器·学习·华为·harmonyos·鸿蒙
未来之窗软件服务3 小时前
企业自动化运营-电子合同预览-东方仙盟
运维·自动化·仙盟创梦ide·东方仙盟
Android系统攻城狮3 小时前
Linux PipeWire深度解析之pw_properties_iterate调用流程与实战(六十五)
linux·运维·服务器·音频进阶·pipewire音频进阶
研华科技Advantech4 小时前
案例 | 从离线巡检到在线看护:研华PHM解决方案赋能石油钻井平台智能运维
运维·人工智能·边缘计算
難釋懷4 小时前
Nginx主动健康检查
运维·nginx
ITyunwei09874 小时前
内存溢出报错,实战处理记录
运维·服务器·企业微信
Elastic 中国社区官方博客4 小时前
你的 AI agent 不需要你的 API 密钥:使用 OAuth 2.1 对 Elasticsearch MCP 服务器进行身份验证
大数据·运维·人工智能·elasticsearch·搜索引擎·全文检索
FreeTinker4 小时前
AP AC组网中的远程运维挑战及内网穿透技术应用分析
运维