zoukankan      html  css  js  c++  java
  • jenkins -- Generic Webhook Trigger插件

    此插件是git webhook的高阶应用,安装后会暴露出来一个公共API,GWT插件接收到 JSON 或 XML 的 HTTP POST 请求后,根据我们配置的规则决定触发哪个Jenkins项目。
    定义需要的变量

    定义token,此token将用于gitlab的调用

    正则匹配,只能匹配到设定的规则还会触发构建,只有满足 production与master分支,且git项目名满足匹配字母或- 大于1个,且触发者(代码提交者)不能是yh,才能触发构建。

    在gitlab项目里添加webhook
    https://jenkins.example.com/generic-webhook-trigger/invoke?token=xxxxx

    点击触发测试

    效果,可以成功触发

    gitlab传递到jenkins的数据在gitlab的webhook url的编辑里面 view detail,可自行获取想要的变量值

    {
      "object_kind": "push",
      "event_name": "push",
      "before": "a2e3c8d96b30967da1fa9579096d52c2b3757d2a",
      "after": "9ff547f1010f40c54aefe693d32c026cfc7d8f4d",
      "ref": "refs/heads/master",
      "checkout_sha": "9ff547f1010f40c54aefe693d32c026cfc7d8f4d",
      "message": null,
      "user_id": 324,
      "user_name": "h_y",
      "user_username": "h_y",
      "user_email": "",
      "user_avatar": null,
      "project_id": 3199,
      "project": {
        "id": 3199,
        "name": "hello",
        "description": "",
        "web_url": "http://gitlab.example.com/h_y/hello",
        "avatar_url": null,
        "git_ssh_url": "git@gitlab.example.com:h_y/hello.git",
        "git_http_url": "http://gitlab.example.com/h_y/hello.git",
        "namespace": "h_y",
        "visibility_level": 0,
        "path_with_namespace": "h_y/hello",
        "default_branch": "master",
        "ci_config_path": null,
        "homepage": "http://gitlab.example.com/h_y/hello",
        "url": "git@gitlab.example.com:h_y/hello.git",
        "ssh_url": "git@gitlab.example.com:h_y/hello.git",
        "http_url": "http://gitlab.example.com/h_y/hello.git"
      },
      "commits": [
        {
          "id": "9ff547f1010f40c54aefe693d32c026cfc7d8f4d",
          "message": "type
    ",
          "title": "type",
          "timestamp": "2020-05-28T15:09:37+08:00",
          "url": "http://gitlab.example.com/h_y/hello/-/commit/9ff547f1010f40c54aefe693d32c026cfc7d8f4d",
          "author": {
            "name": "h_y",
            "email": "h_y@example.com"
          },
          "added": [
    
          ],
          "modified": [
            "Jenkinsfile"
          ],
          "removed": [
    
          ]
        },
        {
          "id": "a49de07609ad97132c0c42aca35c75694ab80085",
          "message": "type
    ",
          "title": "type",
          "timestamp": "2020-05-28T15:08:47+08:00",
          "url": "http://gitlab.example.com/h_y/hello/-/commit/a49de07609ad97132c0c42aca35c75694ab80085",
          "author": {
            "name": "h_y",
            "email": "h_y@example.com"
          },
          "added": [
    
          ],
          "modified": [
            "Jenkinsfile"
          ],
          "removed": [
    
          ]
        },
        {
          "id": "a2e3c8d96b30967da1fa9579096d52c2b3757d2a",
          "message": "type
    ",
          "title": "type",
          "timestamp": "2020-05-28T15:07:58+08:00",
          "url": "http://gitlab.example.com/h_y/hello/-/commit/a2e3c8d96b30967da1fa9579096d52c2b3757d2a",
          "author": {
            "name": "h_y",
            "email": "h_y@example.com"
          },
          "added": [
    
          ],
          "modified": [
            "Jenkinsfile"
          ],
          "removed": [
    
          ]
        }
      ],
      "total_commits_count": 3,
      "push_options": {
      },
      "repository": {
        "name": "hello",
        "url": "git@gitlab.example.com:h_y/hello.git",
        "description": "",
        "homepage": "http://gitlab.example.com/h_y/hello",
        "git_http_url": "http://gitlab.example.com/h_y/hello.git",
        "git_ssh_url": "git@gitlab.example.com:h_y/hello.git",
        "visibility_level": 0
      }
    }
  • 相关阅读:
    Linux系统的tomcat以daemon模式启动并配置成服务202004
    HBuilder android 开发者证书的生成20200416
    【office相关问题】Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效。请确定文件未损坏解决办法
    RHEL6.4服务器整体迁移记录RHEL6.9-2020-操作系统安装在M2固态,应用/数据库重要数据安装至DELL-H310阵列卡RAID1上保证数据安全性
    Linux下将自己安装的Apache(httpd)新增为系统服务,开机自启动
    Linux安装mysql(解压版)tar包解压安装(靠谱版)
    koa2实现jwt登录
    详解js数组扁平化
    快速掌握ES6 iterator Generator和async 之间的关系及其用法
    快速掌握ES6的class用法
  • 原文地址:https://www.cnblogs.com/huandada/p/13067778.html
Copyright © 2011-2022 走看看