前提
使用 Docker 搭建本地 Jenkins 或者 线上服务
注册Gitee账号,并创建一个项目,这里我的项目名是 ui-automation-platform(下面简称UI自动化平台)
Jenkins 集成 Gitee 拉取仓库代码到本地
1、Jenkins内安装Gitee插件
注意:Gitee 相关插件支持 Jenkins 版本 2.3.6以上版本
![](https://img-blog.csdnimg.cn/img_convert/b9befea795fe0ccf0fdc42834b0ae2d2.png)
2、添加凭证
Jenkins首页-设置----Manage Credentials-----全局凭据
![](https://img-blog.csdnimg.cn/img_convert/3a3199769bc44c0d05ba339ce79a013e.png)
![](https://img-blog.csdnimg.cn/img_convert/bdcdd310da4a6bed0892e5913e419105.png)
类型:username with passwor
用户/密码:Gitee账号密码
3、复制 Gitee 仓库地址
![](https://img-blog.csdnimg.cn/img_convert/32034a66af65cc7f54dcf8e6d8204a8a.png)
4、Jenkins内创建/配置项目
![](https://img-blog.csdnimg.cn/img_convert/175fc75c7ea7e77a9406e03375a20315.png)
项目->源码管理
1.选择 Git,配置git
![](https://img-blog.csdnimg.cn/img_convert/02f0b642513e7208b13de85a927c7f1d.png)
Repository URL填写:指定git存储库的URL或路径(图3复制的)
Credentials填写:选择 gitee 全局凭据(图2创建的,连接项目的时候需要用它做校验))
高级 Name填写:origin(源名)
高级 Refspec填写:+refs/heads/*:refs/remotes/origin/* +refs/pull/*/MERGE:refs/pull/*/MERGE (通配符)
点击 应用后保存
5、立即构建
![](https://img-blog.csdnimg.cn/img_convert/61d9a2ac1e5ebdb1947dadb473885ed7.png)
6、构建成功,查看工作空间是否存在代码
![](https://img-blog.csdnimg.cn/img_convert/d991874b7f596318688f13b8c4e49de4.png)
推送代码后 Jenkins自动构建,企业微信推送构建信息。
1、Gitee 配置
首页->系统配置->Configure System
1.添加 Gitee配置
![](https://img-blog.csdnimg.cn/img_convert/d24f59380075dead20d27fa8c7755ef3.png)
链接名:随意写
Gitee 域名 URL 填写:https://gitee.com
2.添加 Gitee 凭据
![](https://img-blog.csdnimg.cn/img_convert/74d1e81ff8dc5d1214ca87a3923bb439.png)
Domlan 选择:全局凭据
类型选择:Gitee API 令牌
Gitee APIV5 私人令牌:https://gitee.com/profile/personal_access_tokens
3.Gitee APIV5私人令牌获取步骤:
获取Gitee 私人令牌
登录Gitee后,点击头像,然后点击【设置】点击【私人令牌】,然后点击【生成新的令牌】
![](https://img-blog.csdnimg.cn/img_convert/fddc1f163b01395174f518d102c5cbe7.png)
填写【私人令牌描述】,点击【提交】
![](https://img-blog.csdnimg.cn/img_convert/2b92f809cbcbadc181f2871bedd326c6.png)
输入【密码】后,生成 私人令牌
![](https://img-blog.csdnimg.cn/img_convert/616ac71038f394a642feb1df44e724b6.png)
复制 私人令牌密码 填入到【Gitee API V5 的私人令牌】内
![](https://img-blog.csdnimg.cn/img_convert/f147e6f129fc4e0a0e296e057e676766.png)
Gitee 私人令牌配置完成
点击 测试链接 返回 【成功】
![](https://img-blog.csdnimg.cn/img_convert/b2c1550e57196de2b7de6ae336f66aa8.png)
2、配置 gitee-ui 项目
1.General
配置 Gitee 链接
![](https://img-blog.csdnimg.cn/img_convert/b84638cc7e38b09e178f000bfdfc98cd.png)
2.构建触发器
勾选 Gitee webhook 触发构建
![](https://img-blog.csdnimg.cn/img_convert/f42ec3b90270f9641b812c26069714af.png)
生成 Gitee WebHook 密码
![](https://img-blog.csdnimg.cn/img_convert/feaa49438ee4160328166ed983675b2b.png)
3.构建后操作
选择 将构建状态评论到 Gitee Pull Request 中
点击【高级】
![](https://img-blog.csdnimg.cn/img_convert/d92a6a1bbcdd9a4303173bd0dec0da99.png)
再次选择 当构建成功自动合并 Gitee 的 Pull Request
![](https://img-blog.csdnimg.cn/img_convert/8ff99940ea5fa9082a9a6cd9d8918fc8.png)
点击 【应用】后,点击【保存】
4.Gitee内配置Webhook
进入仓库内->点击【管理】->选择【WebHooks】
添加【WebHook】
![](https://img-blog.csdnimg.cn/img_convert/90edd309f80f859642d99e66299fad25.png)
添加 webhook:
url: 粘贴 url
webhook密码:粘贴生成的密码
测试【webhook】
![](https://img-blog.csdnimg.cn/img_convert/535adfd7e64dba7edab6c99b1cd845b5.png)
查看更多请求历史以及状态
![](https://img-blog.csdnimg.cn/img_convert/19388d6562b7426940cbeb42a46d4655.png)
注意:添加webhook url内只能添加可以外部访问的jenkins url,否则测试webhook时 会返回 请求超时。
本地jenkins url 如何访问呢!可以使用 花生壳 软件实现对外开放~
5.立即构建
![](https://img-blog.csdnimg.cn/img_convert/231bc68974389a0dd97ead93b0fa7588.png)
3、本地推送代码,jenkins自动构建
![](https://img-blog.csdnimg.cn/img_convert/77909138704284d6c4b643cac022f502.png)
1.企业微信推送构建信息
![](https://img-blog.csdnimg.cn/img_convert/2644f62677646fc3de5a533017abbac8.png)
2.Jenkins自动构建
![](https://img-blog.csdnimg.cn/img_convert/713dad014eea7a025dc7d86302311ef4.png)
至此 Jenkins集成Gitee 讲解完成