type
status
date
slug
summary
tags
category
icon
password
💡
Jenkins部署前后端

1、前端构建

创建一个【自由风格】的任务

notion image

点击【源码管理】

  • 填写(选择)项目仓库的地址和用户
  • 指定要构建的版本,即项目仓库的远程版本号
notion image

选择nodejs版本

如果没有选项,说明当前jenkins 没有安装
notion image

填写构建的命令

这个命令取决于具体工程,和本地第一次执行命令基本一致
上述例子意思大致为,获取项目依赖,并打包构建,然后把打好的包压缩
notion image

传输打包的文件到指定服务器

【SSH Server】:选择要传输文件的服务器
Transfers
  • 【Source files】:写你要传输的文件路径
  • 【Remove prefix】:要去掉的前缀,不写远程服务器的目录结构将和Source files写的一致
  • 【Remote directory】:写你要部署在远程服务器的那个目录地址下,不写就是SSH Servers配置里默认远程目录
  • 【Exec command】:传输完了要执行的命令,图中例子是 进入目录,解压缩,解压缩完成后删除压缩包三个命令
notion image

2、后端构建

创建maven任务

notion image

任务的全局设置

  • 指定jdk版本
notion image

点击【源码管理】

  • 填写(选择)项目仓库的地址和用户
  • 指定要构建的版本,即项目仓库的远程版本号
notion image
notion image

构建时,指定pom文件

  • 跳过测试构建(非必须)
notion image

设置只用构建成功的包

notion image

传输打包的文件到指定服务器

【SSH Server】:选择要传输文件的服务器
Transfers
  • 【Source files】:写你要传输的文件路径
  • 【Remove prefix】:要去掉的前缀,不写远程服务器的目录结构将和Source files写的一致
  • 【Remote directory】:写你要部署在远程服务器的那个目录地址下,不写就是SSH Servers配置里默认远程目录
  • 【Exec command】:传输完了要执行的命令
notion image
 

3、Jenkins自动化构建(钩子)

设置触发自动化构建的条件

下图框中部分为触发自动构建的条件,本例子触发条件的为【提交事件】
notion image
 

设置分支过滤

本例没有做限制
notion image
 

GitLab设置

  • 复制URL
notion image
• 点击Generate按钮,token就会自动生成Secret token
notion image
 
• URL和Secret token,设置在对应的仓库中
notion image
 

测试

notion image
• GitLab页面提示下图内容,则成功触发Jenkins构建任务
notion image
• Jenkins构建历史已有记录
notion image
 
 

4、项目配置私服

  • 仓库setting.xml文件配置私服用户密码
notion image
由于jenkins是docker部署的,会牵扯到一个访问地址
  • 如果是本地获取私服包,则需要在项目的根部pom.xml 配置私服地址
注:id要和setting.xml文件中一致
notion image
 
💡
如果是Jenkins构建,则需要把项目的根部pom.xml 改成下图中的ip
notion image
CertBot申请证书【诺兰电影混剪 】(Time to Pretend)