type
status
date
slug
summary
tags
category
icon
password
Jenkins部署前后端
1、前端构建
创建一个【自由风格】的任务
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Fb43d551f-5653-4baa-b810-729e6f836c39%2FUntitled.png?table=block&id=bd7a13d7-b244-4808-971f-a13895657b45&t=bd7a13d7-b244-4808-971f-a13895657b45&width=1678&cache=v2)
点击【源码管理】
- 填写(选择)项目仓库的地址和用户
- 指定要构建的版本,即项目仓库的远程版本号
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Ffcd0606a-74f7-4073-b7c1-b876f3e510ba%2FUntitled.png?table=block&id=680d059b-e664-4ac2-924c-460a0d47d610&t=680d059b-e664-4ac2-924c-460a0d47d610&width=798&cache=v2)
选择nodejs版本
如果没有选项,说明当前jenkins 没有安装
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Fa08b5c35-f0e9-49cc-ab7f-2753758c1a1d%2FUntitled.png?table=block&id=5bc07c0d-a16d-48e1-ab66-9632f1d93598&t=5bc07c0d-a16d-48e1-ab66-9632f1d93598&width=811&cache=v2)
填写构建的命令
这个命令取决于具体工程,和本地第一次执行命令基本一致
上述例子意思大致为,获取项目依赖,并打包构建,然后把打好的包压缩
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F9a23356d-1405-4ff5-a5e7-2d88be899e2b%2FUntitled.png?table=block&id=d785edb5-5ef8-4a2f-a0ce-c5f4e47d81a4&t=d785edb5-5ef8-4a2f-a0ce-c5f4e47d81a4&width=727&cache=v2)
传输打包的文件到指定服务器
【SSH Server】:选择要传输文件的服务器
Transfers
- 【Source files】:写你要传输的文件路径
- 【Remove prefix】:要去掉的前缀,不写远程服务器的目录结构将和Source files写的一致
- 【Remote directory】:写你要部署在远程服务器的那个目录地址下,不写就是SSH Servers配置里默认远程目录
- 【Exec command】:传输完了要执行的命令,图中例子是 进入目录,解压缩,解压缩完成后删除压缩包三个命令
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Fe9e936ba-26dc-485a-8659-948e784210d8%2FUntitled.png?table=block&id=1fe297b9-3efc-46c1-8312-b373d3d3255c&t=1fe297b9-3efc-46c1-8312-b373d3d3255c&width=686&cache=v2)
2、后端构建
创建maven任务
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Fbb6741b8-e102-4aa0-b2bd-53548191fcfb%2FUntitled.png?table=block&id=01d11f22-d937-4739-94f5-aea7fecc9e57&t=01d11f22-d937-4739-94f5-aea7fecc9e57&width=998&cache=v2)
任务的全局设置
- 指定jdk版本
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F5b2f3b1b-7188-44ef-94fe-9d7e8e660630%2FUntitled.png?table=block&id=2847ba41-b452-4a27-8cab-611746a87c8a&t=2847ba41-b452-4a27-8cab-611746a87c8a&width=957&cache=v2)
点击【源码管理】
- 填写(选择)项目仓库的地址和用户
- 指定要构建的版本,即项目仓库的远程版本号
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Fa2d32d1b-f998-47f5-a54a-05fea94bc134%2FUntitled.png?table=block&id=3302cae2-78df-4241-b15f-2478e5e69abc&t=3302cae2-78df-4241-b15f-2478e5e69abc&width=958&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F0b9f1242-4357-46d9-a7a6-7c11560535a0%2FUntitled.png?table=block&id=27b320dc-f51b-4404-9194-34385cd8d605&t=27b320dc-f51b-4404-9194-34385cd8d605&width=953&cache=v2)
构建时,指定pom文件
- 跳过测试构建(非必须)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F15ae5a20-573f-418a-9ffb-873e172de0bf%2FUntitled.png?table=block&id=9d7baf00-7446-475d-a192-894705dffa43&t=9d7baf00-7446-475d-a192-894705dffa43&width=831&cache=v2)
设置只用构建成功的包
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Fecbf9d7c-e30a-4716-9816-1e5e9794f817%2FUntitled.png?table=block&id=4fb5e4ae-1ddc-41c0-9aa8-dc8fa1400b46&t=4fb5e4ae-1ddc-41c0-9aa8-dc8fa1400b46&width=846&cache=v2)
传输打包的文件到指定服务器
【SSH Server】:选择要传输文件的服务器
Transfers
- 【Source files】:写你要传输的文件路径
- 【Remove prefix】:要去掉的前缀,不写远程服务器的目录结构将和Source files写的一致
- 【Remote directory】:写你要部署在远程服务器的那个目录地址下,不写就是SSH Servers配置里默认远程目录
- 【Exec command】:传输完了要执行的命令
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F3cad8e5a-2d38-484f-86f2-21c708af2571%2FUntitled.png?table=block&id=9534e644-fb4c-4a21-9342-89e0a40e0788&t=9534e644-fb4c-4a21-9342-89e0a40e0788&width=826&cache=v2)
3、Jenkins自动化构建(钩子)
设置触发自动化构建的条件
下图框中部分为触发自动构建的条件,本例子触发条件的为【提交事件】
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Ff51a5247-cba3-4c46-8b12-b16e9dabe9dc%2FUntitled.png?table=block&id=c554cf92-8f40-423c-ad5f-fd31df0e376a&t=c554cf92-8f40-423c-ad5f-fd31df0e376a&width=1274&cache=v2)
设置分支过滤
本例没有做限制
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F07bf82fd-9f1e-46b1-8902-76cfc494e2e0%2FUntitled.png?table=block&id=cf8444b3-2ed4-49ad-b942-ac83fb6068a1&t=cf8444b3-2ed4-49ad-b942-ac83fb6068a1&width=810&cache=v2)
GitLab设置
- 复制URL
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F8274aee3-e45d-49e4-874e-dd7ffead2a86%2FUntitled.png?table=block&id=40ea55b5-0b0c-4fa7-834d-f682d81dc239&t=40ea55b5-0b0c-4fa7-834d-f682d81dc239&width=1299&cache=v2)
• 点击Generate按钮,token就会自动生成Secret token
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F07d3a7ce-d938-44d6-862f-483107710fca%2FUntitled.png?table=block&id=5871092a-1895-4180-b9ff-ecca55232421&t=5871092a-1895-4180-b9ff-ecca55232421&width=892&cache=v2)
• URL和Secret token,设置在对应的仓库中
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F2c31970b-3da7-4242-8fca-828b85e4a2ce%2FUntitled.png?table=block&id=772610a4-75fc-4526-ae46-945d04ed8ec7&t=772610a4-75fc-4526-ae46-945d04ed8ec7&width=1698&cache=v2)
测试
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F3c1b638e-66bc-459f-bb63-46484618934a%2FUntitled.png?table=block&id=3df169d5-23fe-49af-ac0c-8a43a85f5d19&t=3df169d5-23fe-49af-ac0c-8a43a85f5d19&width=562&cache=v2)
• GitLab页面提示下图内容,则成功触发Jenkins构建任务
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Fd33d70df-6404-48f1-a9b7-2fdedee5d1db%2FUntitled.png?table=block&id=2af3af9a-f285-49fd-9116-0e2d638b3b5f&t=2af3af9a-f285-49fd-9116-0e2d638b3b5f&width=375&cache=v2)
• Jenkins构建历史已有记录
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F5d097d5d-1d24-4870-b089-91172093f588%2FUntitled.png?table=block&id=8a0042f2-d789-4fff-8f75-10bfcab9c855&t=8a0042f2-d789-4fff-8f75-10bfcab9c855&width=415&cache=v2)
4、项目配置私服
- 仓库setting.xml文件配置私服用户密码
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2F796c1d38-288d-4d23-917b-76debfcce4d3%2FUntitled.png?table=block&id=ec405521-3d69-4056-bd60-5dac5e29f484&t=ec405521-3d69-4056-bd60-5dac5e29f484&width=465&cache=v2)
由于jenkins是docker部署的,会牵扯到一个访问地址
- 如果是本地获取私服包,则需要在项目的根部pom.xml 配置私服地址
注:id要和setting.xml文件中一致
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Fd86d5931-5217-4fd3-a1a1-680ce5326942%2FUntitled.png?table=block&id=72a24f95-db02-45b2-a7d5-0b508d80a62a&t=72a24f95-db02-45b2-a7d5-0b508d80a62a&width=1031&cache=v2)
如果是Jenkins构建,则需要把项目的根部pom.xml 改成下图中的ip
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fbe23f5eb-2746-4139-b163-dae75ffc3a4b%2Fb012ad06-c35e-4118-93ae-ffdadd9a3034%2FUntitled.png?table=block&id=9f96ec37-574f-4093-86c6-b5400c0d9565&t=9f96ec37-574f-4093-86c6-b5400c0d9565&width=582&cache=v2)
- 作者:十十乙
- 链接:https://shishiyi.cc/article/5fa6878e-c67f-4710-8f3d-799a5054069e
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。