jenkins hook data acquisition and processing GitLab

jenkins hook data acquisition and processing GitLab

jenkinsInstall Generic Webhook Trigger Pluginplug-ins

{% asset_img Generic_Webhook_Trgger.png Generic Webhook Trgger具体配置 %}

Create a task in 构建触发器中check Generic Webhook Trigger, there will be a page in the expanded URL, this URLis the configuration Webhookused, the general form is http://JENKINS_URL/generic-webhook-trigger/invoke, JENKINS_URLis the initial configuration jenkinswill have the time, usually http://IP:8080in the form.

If you have been previously configured GitLab webhook, please remove this, or Generic Webhook Triggerwill not take effect.

If the Gitverification warehouse using a user name and password, you do not need to configure Token.

This copy URLwill be JENKINS_URLreplaced by their real data, the GitLabcorresponding item 设置-->集成in the input, there is no security token, check the trigger event they need, SSL certificate validation can be turned on, it can not open, it is recommended to open.

Task settings interface as well as Post content parameters, Header parameters, Request parameters, respectively, requested post数据, header头, 请求头.

Generally, we only need postthe data of the contents is enough.

Pictures 3,4 respectively 变量名(3), 值(4). Value directly from postthe json格式data taken out, it is noted that the value acquisition mode JSONPath, and there , if jsondata is multilayer, then several times more, for example $.project.namesuch groups may be a plurality of variables.

We can also Generic Webhook Triggerconfigure Optional filter, set up a trigger event, such as only when you push the branch is developwhen we come to build.

In Optional filterthe Expressioninput box ^(refs/heads/develop)$, in the following Textbox, enter 步骤3的变量名, write here $ref.

In shellusing the variable name is used directly in the way, for example echo $ref, did not pay attention .

Once configured, save, you can just click on the configuration of GitLabthe webhookpage Testcorresponding event test.

GitLabOf pushthe hookdata:

{
  "object_kind": "push",
  "before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
  "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
  "ref": "refs/heads/master",
  "checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
  "user_id": 4,
  "user_name": "John Smith",
  "user_username": "jsmith",
  "user_email": "[email protected]",
  "user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
  "project_id": 15,
  "project":{
    "id": 15,
    "name":"Diaspora",
    "description":"",
    "web_url":"http://example.com/mike/diaspora",
    "avatar_url":null,
    "git_ssh_url":"[email protected]:mike/diaspora.git",
    "git_http_url":"http://example.com/mike/diaspora.git",
    "namespace":"Mike",
    "visibility_level":0,
    "path_with_namespace":"mike/diaspora",
    "default_branch":"master",
    "homepage":"http://example.com/mike/diaspora",
    "url":"[email protected]:mike/diaspora.git",
    "ssh_url":"[email protected]:mike/diaspora.git",
    "http_url":"http://example.com/mike/diaspora.git"
  },
  "repository":{
    "name": "Diaspora",
    "url": "[email protected]:mike/diaspora.git",
    "description": "",
    "homepage": "http://example.com/mike/diaspora",
    "git_http_url":"http://example.com/mike/diaspora.git",
    "git_ssh_url":"[email protected]:mike/diaspora.git",
    "visibility_level":0
  },
  "commits": [
    {
      "id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
      "message": "Update Catalan translation to e38cb41.",
      "timestamp": "2011-12-12T14:27:31+02:00",
      "url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
      "author": {
        "name": "Jordi Mallach",
        "email": "[email protected]"
      },
      "added": ["CHANGELOG"],
      "modified": ["app/controller/application.rb"],
      "removed": []
    },
    {
      "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
      "message": "fixed readme",
      "timestamp": "2012-01-03T23:36:29+02:00",
      "url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
      "author": {
        "name": "GitLab dev user",
        "email": "gitlabdev@dv6700.(none)"
      },
      "added": ["CHANGELOG"],
      "modified": ["app/controller/application.rb"],
      "removed": []
    }
  ],
  "total_commits_count": 4
}

Guess you like

Origin www.cnblogs.com/zzhaolei/p/11068007.html