GitLab:编辑合并请求描述会触发发送合并请求挂钩
GitLab: Editing the merge request description triggers a merge request hook being sent
对于我在 GitLab 上的存储库,我配置了一个 Merge Request Hook,它会触发 Jenkins CI 机器上的构建。打开合并请求时,挂钩会按预期工作。
webhook 配置了以下触发器:
- URL: https://example.com/project/ExampleApp_merge_requests
- 推送事件:已启用
- 合并请求事件:已启用
- 启用 SSL 验证:关闭
最近,当我编辑合并请求的描述 时,挂钩也会通知CI 机器。
这是一个示例 POST 请求:
请求headers:
Content-Type: application/json
X-Gitlab-Event: Merge Request Hook
请求body:
{
"object_kind": "merge_request",
"event_type": "merge_request",
"user": {
"name": "User Name",
"username": "username",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/145/avatar.png"
},
"project": {
"id": 39,
"name": "app",
"description": "Lorem ipsum.",
"web_url": "https://gitlab.example.com/projects/app",
"avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
"git_ssh_url": "git@gitlab.example.com:projects/app.git",
"git_http_url": "https://gitlab.example.com/projects/app.git",
"namespace": "projects",
"visibility_level": 0,
"path_with_namespace": "projects/app",
"default_branch": "develop",
"ci_config_path": null,
"homepage": "https://gitlab.example.com/projects/app",
"url": "git@gitlab.example.com:projects/app.git",
"ssh_url": "git@gitlab.example.com:projects/app.git",
"http_url": "https://gitlab.example.com/projects/app.git"
},
"object_attributes": {
"assignee_id": null,
"author_id": 5,
"created_at": "2019-03-19 16:42:28 UTC",
"description": "- s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\n- Lorem ipsum.",
"head_pipeline_id": 7473,
"id": 9258,
"iid": 844,
"last_edited_at": "2019-03-20 09:00:21 UTC",
"last_edited_by_id": 145,
"merge_commit_sha": null,
"merge_error": null,
"merge_params": {
"force_remove_source_branch": "1"
},
"merge_status": "can_be_merged",
"merge_user_id": null,
"merge_when_pipeline_succeeds": false,
"milestone_id": null,
"source_branch": "fix/random",
"source_project_id": 39,
"state": "opened",
"target_branch": "develop",
"target_project_id": 39,
"time_estimate": 0,
"title": "Fix random",
"updated_at": "2019-03-20 09:00:21 UTC",
"updated_by_id": 145,
"url": "https://gitlab.example.com/projects/app/merge_requests/844",
"source": {
"id": 39,
"name": "app",
"description": "Lorem ipsum.",
"web_url": "https://gitlab.example.com/projects/app",
"avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
"git_ssh_url": "git@gitlab.example.com:projects/app.git",
"git_http_url": "https://gitlab.example.com/projects/app.git",
"namespace": "projects",
"visibility_level": 0,
"path_with_namespace": "projects/app",
"default_branch": "develop",
"ci_config_path": null,
"homepage": "https://gitlab.example.com/projects/app",
"url": "git@gitlab.example.com:projects/app.git",
"ssh_url": "git@gitlab.example.com:projects/app.git",
"http_url": "https://gitlab.example.com/projects/app.git"
},
"target": {
"id": 39,
"name": "app",
"description": "Lorem ipsum.",
"web_url": "https://gitlab.example.com/projects/app",
"avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
"git_ssh_url": "git@gitlab.example.com:projects/app.git",
"git_http_url": "https://gitlab.example.com/projects/app.git",
"namespace": "projects",
"visibility_level": 0,
"path_with_namespace": "projects/app",
"default_branch": "develop",
"ci_config_path": null,
"homepage": "https://gitlab.example.com/projects/app",
"url": "git@gitlab.example.com:projects/app.git",
"ssh_url": "git@gitlab.example.com:projects/app.git",
"http_url": "https://gitlab.example.com/projects/app.git"
},
"last_commit": {
"id": "cdda6f7d200468955ecbd224f0437932db607087",
"message": "Fix random\n\n",
"timestamp": "2019-03-20T08:45:40Z",
"url": "https://gitlab.example.com/projects/app/commit/cdda6f7d200468955ecbd224f0437932db607087",
"author": {
"name": "User Name",
"email": "username"
}
},
"work_in_progress": false,
"total_time_spent": 0,
"human_total_time_spent": null,
"human_time_estimate": null,
"action": "update"
},
"labels": [
{
"id": 22,
"title": "Bug fix",
"color": "#FF0000",
"project_id": null,
"created_at": "2018-10-19 09:55:26 UTC",
"updated_at": "2018-11-05 15:17:08 UTC",
"template": false,
"description": "",
"type": "GroupLabel",
"group_id": 15
}
],
"changes": {
"description": {
"previous": "s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\nLorem ipsum.",
"current": "- s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\n- Lorem ipsum."
},
"last_edited_at": {
"previous": "2019-03-19 16:42:50 UTC",
"current": "2019-03-20 09:00:21 UTC"
},
"last_edited_by_id": {
"previous": 5,
"current": 145
},
"updated_at": {
"previous": "2019-03-20 08:52:38 UTC",
"current": "2019-03-20 09:00:21 UTC"
},
"updated_by_id": {
"previous": 5,
"current": 145
}
},
"repository": {
"name": "app",
"url": "git@gitlab.example.com:projects/app.git",
"description": "Lorem ipsum.",
"homepage": "https://gitlab.example.com/projects/app"
}
}
回复headers:
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 20 Mar 2019 09:00:21 GMT
Transfer-Encoding: chunked
Connection: close
X-Content-Type-Options: nosniff
Jenkins 插件如下所示:
在 Jenkins 机器上安装了以下 GitLab 插件:
- Jenkins GitLab OAuth Plugin
- Jenkins GitLab Hook Plugin
- Jenkins GitLab Logo Plugin
- GitLab Merge Request Builder Plugin
- GitLab Plugin
创建或更新拉取请求的分支时,如何配置 POST 请求仅发送到 CI 机器?
在触发器(设置 -> 集成)下执行以下操作:
- 启用推送事件(可选分支名称 - 甚至在 MR 可能之前通过推送事件创建分支)
- 在您的项目仓库中启用 MR 事件触发器
This URL will be triggered when a merge request is created/updated/merged
在 Jenkins 插件配置中 -
- 检查"Push Events"(任何通过直接推送或创建的方式提交)
- 取消勾选"Opened Merge Request Events"
- 检查 "Accepted Merge Request Events"(通过合并请求进行的任何提交)
无所事事突然解决了这个问题。在当前的软件堆栈中,我不再遇到这个问题。
这是软件版本:
- 詹金斯 2.204
- GitLab 插件 1.5.13
- GitLab 企业版 12.4.2-ee
希望对其他人有所帮助。
对于我在 GitLab 上的存储库,我配置了一个 Merge Request Hook,它会触发 Jenkins CI 机器上的构建。打开合并请求时,挂钩会按预期工作。
webhook 配置了以下触发器:
- URL: https://example.com/project/ExampleApp_merge_requests
- 推送事件:已启用
- 合并请求事件:已启用
- 启用 SSL 验证:关闭
最近,当我编辑合并请求的描述 时,挂钩也会通知CI 机器。
这是一个示例 POST 请求:
请求headers:
Content-Type: application/json
X-Gitlab-Event: Merge Request Hook
请求body:
{
"object_kind": "merge_request",
"event_type": "merge_request",
"user": {
"name": "User Name",
"username": "username",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/145/avatar.png"
},
"project": {
"id": 39,
"name": "app",
"description": "Lorem ipsum.",
"web_url": "https://gitlab.example.com/projects/app",
"avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
"git_ssh_url": "git@gitlab.example.com:projects/app.git",
"git_http_url": "https://gitlab.example.com/projects/app.git",
"namespace": "projects",
"visibility_level": 0,
"path_with_namespace": "projects/app",
"default_branch": "develop",
"ci_config_path": null,
"homepage": "https://gitlab.example.com/projects/app",
"url": "git@gitlab.example.com:projects/app.git",
"ssh_url": "git@gitlab.example.com:projects/app.git",
"http_url": "https://gitlab.example.com/projects/app.git"
},
"object_attributes": {
"assignee_id": null,
"author_id": 5,
"created_at": "2019-03-19 16:42:28 UTC",
"description": "- s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\n- Lorem ipsum.",
"head_pipeline_id": 7473,
"id": 9258,
"iid": 844,
"last_edited_at": "2019-03-20 09:00:21 UTC",
"last_edited_by_id": 145,
"merge_commit_sha": null,
"merge_error": null,
"merge_params": {
"force_remove_source_branch": "1"
},
"merge_status": "can_be_merged",
"merge_user_id": null,
"merge_when_pipeline_succeeds": false,
"milestone_id": null,
"source_branch": "fix/random",
"source_project_id": 39,
"state": "opened",
"target_branch": "develop",
"target_project_id": 39,
"time_estimate": 0,
"title": "Fix random",
"updated_at": "2019-03-20 09:00:21 UTC",
"updated_by_id": 145,
"url": "https://gitlab.example.com/projects/app/merge_requests/844",
"source": {
"id": 39,
"name": "app",
"description": "Lorem ipsum.",
"web_url": "https://gitlab.example.com/projects/app",
"avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
"git_ssh_url": "git@gitlab.example.com:projects/app.git",
"git_http_url": "https://gitlab.example.com/projects/app.git",
"namespace": "projects",
"visibility_level": 0,
"path_with_namespace": "projects/app",
"default_branch": "develop",
"ci_config_path": null,
"homepage": "https://gitlab.example.com/projects/app",
"url": "git@gitlab.example.com:projects/app.git",
"ssh_url": "git@gitlab.example.com:projects/app.git",
"http_url": "https://gitlab.example.com/projects/app.git"
},
"target": {
"id": 39,
"name": "app",
"description": "Lorem ipsum.",
"web_url": "https://gitlab.example.com/projects/app",
"avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
"git_ssh_url": "git@gitlab.example.com:projects/app.git",
"git_http_url": "https://gitlab.example.com/projects/app.git",
"namespace": "projects",
"visibility_level": 0,
"path_with_namespace": "projects/app",
"default_branch": "develop",
"ci_config_path": null,
"homepage": "https://gitlab.example.com/projects/app",
"url": "git@gitlab.example.com:projects/app.git",
"ssh_url": "git@gitlab.example.com:projects/app.git",
"http_url": "https://gitlab.example.com/projects/app.git"
},
"last_commit": {
"id": "cdda6f7d200468955ecbd224f0437932db607087",
"message": "Fix random\n\n",
"timestamp": "2019-03-20T08:45:40Z",
"url": "https://gitlab.example.com/projects/app/commit/cdda6f7d200468955ecbd224f0437932db607087",
"author": {
"name": "User Name",
"email": "username"
}
},
"work_in_progress": false,
"total_time_spent": 0,
"human_total_time_spent": null,
"human_time_estimate": null,
"action": "update"
},
"labels": [
{
"id": 22,
"title": "Bug fix",
"color": "#FF0000",
"project_id": null,
"created_at": "2018-10-19 09:55:26 UTC",
"updated_at": "2018-11-05 15:17:08 UTC",
"template": false,
"description": "",
"type": "GroupLabel",
"group_id": 15
}
],
"changes": {
"description": {
"previous": "s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\nLorem ipsum.",
"current": "- s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\n- Lorem ipsum."
},
"last_edited_at": {
"previous": "2019-03-19 16:42:50 UTC",
"current": "2019-03-20 09:00:21 UTC"
},
"last_edited_by_id": {
"previous": 5,
"current": 145
},
"updated_at": {
"previous": "2019-03-20 08:52:38 UTC",
"current": "2019-03-20 09:00:21 UTC"
},
"updated_by_id": {
"previous": 5,
"current": 145
}
},
"repository": {
"name": "app",
"url": "git@gitlab.example.com:projects/app.git",
"description": "Lorem ipsum.",
"homepage": "https://gitlab.example.com/projects/app"
}
}
回复headers:
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 20 Mar 2019 09:00:21 GMT
Transfer-Encoding: chunked
Connection: close
X-Content-Type-Options: nosniff
Jenkins 插件如下所示:
在 Jenkins 机器上安装了以下 GitLab 插件:
- Jenkins GitLab OAuth Plugin
- Jenkins GitLab Hook Plugin
- Jenkins GitLab Logo Plugin
- GitLab Merge Request Builder Plugin
- GitLab Plugin
创建或更新拉取请求的分支时,如何配置 POST 请求仅发送到 CI 机器?
在触发器(设置 -> 集成)下执行以下操作:
- 启用推送事件(可选分支名称 - 甚至在 MR 可能之前通过推送事件创建分支)
- 在您的项目仓库中启用 MR 事件触发器
This URL will be triggered when a merge request is created/updated/merged
在 Jenkins 插件配置中 -
- 检查"Push Events"(任何通过直接推送或创建的方式提交)
- 取消勾选"Opened Merge Request Events"
- 检查 "Accepted Merge Request Events"(通过合并请求进行的任何提交)
无所事事突然解决了这个问题。在当前的软件堆栈中,我不再遇到这个问题。
这是软件版本:
- 詹金斯 2.204
- GitLab 插件 1.5.13
- GitLab 企业版 12.4.2-ee
希望对其他人有所帮助。