准备
因为要与Gitlab通讯,所以Jenkins需要安装插件 Gitlab Plugin
配置Gitlab参数
进入Jenkins的系统配置页面,找到Gitlab设置项,点击增加
connection name: gitlab <-- 写个名字能任的出来就好
gitlab host url: http://gitlab.host <-- gitlab的地址
Apitoken:具体配置方式如下
类型选择 secret text
登录gitlab,在个人账号的 Profile settings -> account中,把 Private token的值复制出来,填写到Jenkins中后保存
填写好以后点击 **testconnection按钮** 进行测试,如果结果显示 success 则说明参数填写正确,该配置可用

Jenkins中任务的设置
- 进入Job的新增或者编辑页面,找到 构建触发器 选项,选中 Build when a change is pushed to GitLab
- 其他选项可以默认不改

Gitlab中的设置
把 http://gitlabhost/project/jobname 这个链接配置到gitlab对应的project中,具体配置如下
- 进入gitlab,找到对应的代码仓库,进入settings
- 进入webhooks页面
- 把上面的url填写到url字段中
- trigger选择对应的选项
- 点击 add webhook按钮保存
- 点击下方的 test hook按钮, 页面上显示 Hook successfully executed. 后说明配置生效

网友评论