<commit_before>---
layout: post
title: SpringBoot+Docker+Git+Jenkins实现简易的持续集成和持续部署
categories: 微服务
description: 微服务
keywords: 微服务
---

> 努力了这么久，但凡有点儿天赋，也该有些成功的迹象了。

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png")

## 前言 ##

本篇文章引导你使用`Jenkins`部署`SpringBoot`项目,同时使用`Docker`和`Git`实现简单的[持续集成](https://baike.baidu.com/item/%E6%8C%81%E7%BB%AD%E9%9B%86%E6%88%90)和持续部署。（项目地址：[sso-merryyou](https://github.com/longfeizheng/sso-merryyou)）

流程图如下：

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png")

1. `push`代码到`Github`触发`WebHook`。（因网络原因，本篇使用[gitee](https://gitee.com/merryyou/sso-merryyou)）
2. `Jenkins`从仓库拉去代码
3. `mavem`构建项目
4. 代码静态分析
5. 单元测试
6. `build`镜像
7. `push`镜像到镜像仓库（本篇使用的镜像仓库为网易镜像仓库）
8. 更新服务


### Jenkins安装

从[https://jenkins.io/download/](https://jenkins.io/download/)下载对应的`jenkins`

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png")


访问本地：[http://localhost:8080](http://localhost:8080)输入密码

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png")

进入用户自定义插件界面，选择第二个（因为我们本次构建使用的为`Pipelines `）

勾选与`Pipelines `相关的插件

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png")

等待插件安装完成

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png")

配置用户名和密码

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png")

系统管理-》全局工具配置 配置Git,JKD和Maven

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png")

系统管理-》全局安全配置 

- 勾选Allow anonymous read access
- 取消防止跨站点请求伪造

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png")

新建任务-》流水线

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png")

勾选触发远程构建 (WebHooks触发地址)，填写简单的`Pipeline script`

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png")

立即构建

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png")

控制台输出

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png")

### gitee集成WebHooks

添加SSH公匙


[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png")

配置WebHooks

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png")

> 使用[natapp](https://natapp.cn/)实现内网穿透

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png")

### 修改脚本

修改`Pipeline script`
<commit_msg>no message<commit_after>---
layout: post
title: SpringBoot+Docker+Git+Jenkins实现简易的持续集成和持续部署
categories: 微服务
description: 微服务
keywords: 微服务
---

> 努力了这么久，但凡有点儿天赋，也该有些成功的迹象了。

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker03.png")

## 前言 ##

本篇文章引导你使用`Jenkins`部署`SpringBoot`项目,同时使用`Docker`和`Git`实现简单的[持续集成](https://baike.baidu.com/item/%E6%8C%81%E7%BB%AD%E9%9B%86%E6%88%90)和持续部署。（项目地址：[sso-merryyou](https://github.com/longfeizheng/sso-merryyou)）

流程图如下：

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker02.png")

1. `push`代码到`Github`触发`WebHook`。（因网络原因，本篇使用[gitee](https://gitee.com/merryyou/sso-merryyou)）
2. `Jenkins`从仓库拉去代码
3. `mavem`构建项目
4. 代码静态分析
5. 单元测试
6. `build`镜像
7. `push`镜像到镜像仓库（本篇使用的镜像仓库为网易镜像仓库）
8. 更新服务


### Jenkins安装

#### 下载jenkins
从[https://jenkins.io/download/](https://jenkins.io/download/)下载对应的`jenkins`

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker07.png")

#### 初始化密码
访问本地：[http://localhost:8080](http://localhost:8080)输入密码

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker04.png")

####选择插件
进入用户自定义插件界面，选择第二个（因为我们本次构建使用的为`Pipelines `）

勾选与`Pipelines `相关的插件

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker05.png")

等待插件安装完成

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker06.png")

#### 配置用户名和密码


[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker08.png")

#### 全局配置

系统管理-》全局工具配置 配置Git,JDK和Maven

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker09.png")

#### 安全配置
系统管理-》全局安全配置 

- 勾选Allow anonymous read access
- 取消防止跨站点请求伪造

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker10.png")

#### 新建任务
新建任务-》流水线

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker11.png")

#### 构建脚本
勾选触发远程构建 (WebHooks触发地址)，填写简单的`Pipeline script`

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker12.png")

```groovy
#!groovy
pipeline{
	agent any

	stages {

		stage('test'){
			steps {
				echo "hello world"
			
			}
		}			
	}
}
```

#### 测试脚本
立即构建

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker13.png")

#### 打印
控制台输出

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker14.png")

### gitee集成WebHooks


#### 添加SSH公匙


[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker15.png")

#### 配置WebHooks

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker16.png")

> 使用[natapp](https://natapp.cn/)实现内网穿透

[![https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png")](https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png "https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/docker/docker17.png")

### 修改脚本

修改`Pipeline script`

{'fraction_non_alphanumeric': 0.15888809108626525, 'fraction_numerical': 0.019489178377269465, 'mean_word_length': 6.531479335650831, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 172, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7664971', 'n_tokens_mistral': 7884, 'n_tokens_neox': 7519, 'n_words': 237}