前言

当今软件开发行业,代码的构建、集成和部署是一个极其重要的环节。而Jenkins是开发人员在持续集成、持续部署和自动化构建中非常流行的工具。本篇博客将介绍如何在Jenkins上配置自动化拉取GitLab代码并打包的流程。这个过程可以减轻开发人员的工作负担,提高整个团队的效率。

步骤

安装Jenkins插件

  1. 在Jenkins的系统管理-插件管理安装GitLab Plugin插件

    image-20220110173520572

配置

  1. 查看GitLab回调地址,在项目配置,构建触发器可以看到相关配置

    image-20220111093252247

  2. 在GitLab项目Setting-Webhooks页面配置URL

    image-20220111093450247

  3. 找到Project Hooks,选择webhook地址,点击Test

    image-20220111094216629

    看到下面的结果,说明配置成功了。

    image-20220111094205362

  4. 可以根据实际需要,使用触发的事件,如新增Tag时触发

    image-20220111141629153

可能出现问题:出现Url is blocked: Requests to the local network are not allowed

解决方案:在GitLab的Admin Area界面,Settings-Network,将Outbound requests中,勾选允许本地网络请求即可

image-20220111093719667

可能出现问题:Webhook接口403

Hook executed successfully but returned HTTP 403 <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 403 anonymous is missing the Job/Build permission</title> </head> <body><h2>HTTP ERROR 403 anonymous is missing the Job/Build permission</h2> <table> <tr><th>URI:</th><td>/project/test</td></tr> <tr><th>STATUS:</th><td>403</td></tr> <tr><th>MESSAGE:</th><td>anonymous is missing the Job/Build permission</td></tr> <tr><th>SERVLET:</th><td>Stapler</td></tr> </table> <hr><a href="https://eclipse.org/jetty">Powered by Jetty:// 9.4.43.v20210629</a><hr/> </body> </html>

解决方案:在Jenkins配置界面的GitLab配置,将鉴权取消勾选

image-20220111094131284