美文网首页程序员
Gitlab配置Web Hook关联Jenkins实现push后

Gitlab配置Web Hook关联Jenkins实现push后

作者: 张云飞Vir | 来源:发表于2019-03-15 12:34 被阅读0次

    背景

    我想改进我的持续集成流程,想在部门的内部训练项目中做到push到msster 即自动部署到远端服务器。Jenkins是配置好的,我们来实现它。

    实施后效果:

    1. 开发人员: 在develop分支编写代码,测试完后,再合并到 master 分支,push到 gitlab.
    2. Gitlab: 收到 push 后,配置好的 trigger 触发,通知到 jenkins
    3. Jenkins: 收到构建触发器后,即启动构建,配置好的构建脚本被执行,将构建的结果进行部署。

    具体实现步骤

    第一步,Jenkins 构建触发器

    1. 打开jenkins的项目的job, 找到 构建触发器 板块,
    2. 找到板块下的 Build when a change is pushed to GitLab. GitLab webhook URL: http://192.168.135.84:8080/project/discovery_web_deploy

    注意后面的网址 GitLab webhook URL 部分,我们复制下来。

    见下图示例:

    image.png

    第二步,GIT Lab trigger 配置(Web Hook)

    打开项目 settings - Integrations, 会看到介绍:

    Integrations
    Webhooks can be used for binding events when something is happening within the project.
    

    在URL 文本框中填写上面的 GitLab webhook URL 获得的网址。

    image.png

    完成后,可点击 test 测试是否好使。

    image.png

    第三步,根据你的需要,配置指定分支。

    1. 进入到你的jenkins 中的项目job, 点击刚刚设置的触发器,再点击 高级。
    2. 找到 Allowed branches 行,设置 Filter branches by name 的文本框。
    3. 设置完后,点保存。


      image.png

    设置结束, Enjoy It.

    相关文章

      网友评论

        本文标题:Gitlab配置Web Hook关联Jenkins实现push后

        本文链接:https://www.haomeiwen.com/subject/atelmqtx.html