以前在上家公司,管理代码库的工具是Gerrit,所以我们用Gerrit Code Review(Jenkins Gerrit plugin),在人工做code review之前会有Jenkins Auto Verify Job。Verify的内容大致有编译、代码静态检查等。
在现在的工作环境,用公司统一的GitLab工具,code review的流程也只有人工审查,经常会发现不了一些代码改动的问题。一旦代码被merge到主干后,导致daily build失败,无法打出新的包,需要紧急解决,很被动。
于是根据以前的CI经验,对GitLab Code Review做了流程上的优化(Jenkins Gitlab Plugin)。
老的流程如下图:

优化后的流程:增加了黄色虚线圆圈里的部分

Jenkins verify结束,会在GitLab的Merge Request上把Verify的结果推送上去,并进行投票。

配置:
1. 首先在Jenkins上安装Gitlab plugin。
2. Jenkins -> Manager -> System Configure -> Gitlab
URL: gitlab的url
Credentials:登陆到gitlab,获取到API token,在这里Add一个新的credential
配置好后,点击”Test Connection”,如果配置没问题,会看到“Success”

3. Jenkins verify job配置 -> GitLab

4. Jenkins verify job配置 -> GitLab -> 高级

5. Jenkins verify job配置 -> Git
Name: origin
Refspec: +refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*
Branch Specifier (blank for 'any'): origin/${gitlabSourceBranch}

6. Jenkins verify job配置 -> Post-build Actions 添加如下两项才能在GitLab Merge Request上得到Jenkins verify的结果。
"Add note with build status on GitLab merge requests" 给GitLab Merge Request发送成功,失败或者取消的消息。
"Add vote for build statuss on GitLab merge requests" 给GitLab Merge Request发送投票。

7. Gitlab进入到对应的repository -> Settings -> Intergrations -> Add webhook, 同时把Merge Request events的选项勾上。

配置好后,Save changes -> Test -> Merge Request events, 如果看到Status code 200,说明连接正常。

Reference:
网友评论