玩转Jenkins - Jenkins + Gitlab实现代码变更后自动部署

准备

因为要与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 - Jenkins + Gitlab实现代码变更后自动部署》 Paste_Image.png

Jenkins中任务的设置

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

《玩转Jenkins - Jenkins + Gitlab实现代码变更后自动部署》 Paste_Image.png

Gitlab中的设置

http://gitlabhost/project/jobname 这个链接配置到gitlab对应的project中,具体配置如下

  1. 进入gitlab,找到对应的代码仓库,进入settings
  2. 进入webhooks页面
  3. 把上面的url填写到url字段中
  4. trigger选择对应的选项
  5. 点击 add webhook按钮保存
  6. 点击下方的 test hook按钮, 页面上显示 Hook successfully executed. 后说明配置生效

《玩转Jenkins - Jenkins + Gitlab实现代码变更后自动部署》 Paste_Image.png

原文地址:http://fatiao.site/jenkins_codedeploy.html

    原文作者:小发条
    原文地址: https://www.jianshu.com/p/2afadfb9f9b8
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞