jenkins hook data acquisition and processing GitLab
jenkins
Install Generic Webhook Trigger Plugin
plug-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 URL
is the configuration Webhook
used, the general form is http://JENKINS_URL/generic-webhook-trigger/invoke
, JENKINS_URL
is the initial configuration jenkins
will have the time, usually http://IP:8080
in the form.
If you have been previously configured GitLab webhook
, please remove this, or Generic Webhook Trigger
will not take effect.
If the Git
verification warehouse using a user name and password, you do not need to configure Token
.
This copy URL
will be JENKINS_URL
replaced by their real data, the GitLab
corresponding 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 post
the data of the contents is enough.
Pictures 3,4 respectively 变量名(3)
, 值(4)
. Value directly from post
the json格式
data taken out, it is noted that the value acquisition mode JSONPath
, and there 点
, if json
data is multilayer, then several times more, for example $.project.name
such groups may be a plurality of variables.
We can also Generic Webhook Trigger
configure Optional filter
, set up a trigger event, such as only when you push the branch is develop
when we come to build.
In Optional filter
the Expression
input box ^(refs/heads/develop)$
, in the following Text
box, enter 步骤3的变量名
, write here $ref
.
In shell
using 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 GitLab
the webhook
page Test
corresponding event test.
GitLab
Of push
the hook
data:
{
"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
}