type
status
date
slug
summary
tags
category
icon
password
Jenkins部署前后端
1、前端构建
创建一个【自由风格】的任务

点击【源码管理】
- 填写(选择)项目仓库的地址和用户
- 指定要构建的版本,即项目仓库的远程版本号

选择nodejs版本
如果没有选项,说明当前jenkins 没有安装

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

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

2、后端构建
创建maven任务

任务的全局设置
- 指定jdk版本

点击【源码管理】
- 填写(选择)项目仓库的地址和用户
- 指定要构建的版本,即项目仓库的远程版本号


构建时,指定pom文件
- 跳过测试构建(非必须)

设置只用构建成功的包

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

3、Jenkins自动化构建(钩子)
设置触发自动化构建的条件
下图框中部分为触发自动构建的条件,本例子触发条件的为【提交事件】

设置分支过滤
本例没有做限制

GitLab设置
- 复制URL

• 点击Generate按钮,token就会自动生成Secret token

• URL和Secret token,设置在对应的仓库中

测试

• GitLab页面提示下图内容,则成功触发Jenkins构建任务

• Jenkins构建历史已有记录

4、项目配置私服
- 仓库setting.xml文件配置私服用户密码

由于jenkins是docker部署的,会牵扯到一个访问地址
- 如果是本地获取私服包,则需要在项目的根部pom.xml 配置私服地址
注:id要和setting.xml文件中一致

如果是Jenkins构建,则需要把项目的根部pom.xml 改成下图中的ip

- 作者:十十乙
- 链接:https://shishiyi.cc/article/5fa6878e-c67f-4710-8f3d-799a5054069e
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。