{{< details >}}

  1. Tier: 基础版, 专业版, 旗舰版
  2. Offering: 私有化部署

{{< /details >}}

所有方法都需要管理员授权。

您可以从极狐GitLab 用户界面配置系统钩子的 URL 端点:

  1. 在左侧边栏底部,选择 管理员
  2. 选择 系统钩子 (/admin/hooks)。

阅读更多关于系统钩子

列出系统钩子

获取所有系统钩子的列表。

GET /hooks

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks"

示例响应:

[
  {
    "id":1,
    "url":"https://gitlab.example.com/hook",
    "name": "Hook name",
    "description": "Hook description",
    "created_at":"2016-10-31T12:32:15.192Z",
    "push_events":true,
    "tag_push_events":false,
    "merge_requests_events": true,
    "repository_update_events": true,
    "enable_ssl_verification":true,
    "url_variables": []
  }
]

获取系统钩子

通过其 ID 获取系统钩子。

GET /hooks/:id
属性 类型 必需 描述
id integer yes 钩子的 ID

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks/1"

示例响应:

{
  "id": 1,
  "url": "https://gitlab.example.com/hook",
  "name": "Hook name",
  "description": "Hook description",
  "created_at": "2016-10-31T12:32:15.192Z",
  "push_events": true,
  "tag_push_events": false,
  "merge_requests_events": true,
  "repository_update_events": true,
  "enable_ssl_verification": true,
  "url_variables": []
}

添加新系统钩子

添加一个新的系统钩子。

POST /hooks
属性 类型 必需 描述
url string yes 钩子的 URL
name string no 钩子的名称(在 GitLab 17.1 中引入)
description string no 钩子的描述(在 GitLab 17.1 中引入)
token string no 用于验证接收到的负载的密钥,这不会在响应中返回
push_events boolean no 当为 true 时,钩子会在推送事件上触发
tag_push_events boolean no 当为 true 时,钩子会在新的标签被推送时触发
merge_requests_events boolean no 在合并请求事件上触发钩子
repository_update_events boolean no 在仓库更新事件上触发钩子
enable_ssl_verification boolean no 触发钩子时进行 SSL 验证
push_events_branch_filter string no 仅在匹配的分支上触发推送事件的钩子
branch_filter_strategy string no 按分支过滤推送事件。可能的值为 wildcard(默认),regexall_branches

示例请求:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks?url=https://gitlab.example.com/hook"

示例响应:

[
  {
    "id":1,
    "url":"https://gitlab.example.com/hook",
    "name": "Hook name",
    "description": "Hook description",
    "created_at":"2016-10-31T12:32:15.192Z",
    "push_events":true,
    "tag_push_events":false,
    "merge_requests_events": true,
    "repository_update_events": true,
    "enable_ssl_verification":true,
    "url_variables": []
  }
]

更新系统钩子

更新现有的系统钩子。

PUT /hooks/:hook_id
属性 类型 必需 描述
hook_id integer Yes 系统钩子的 ID
url string no 钩子的 URL
token string no 用于验证接收到的负载的密钥,这不会在响应中返回
push_events boolean no 当为 true 时,钩子会在推送事件上触发
tag_push_events boolean no 当为 true 时,钩子会在新的标签被推送时触发
merge_requests_events boolean no 在合并请求事件上触发钩子
repository_update_events boolean no 在仓库更新事件上触发钩子
enable_ssl_verification boolean no 触发钩子时进行 SSL 验证
push_events_branch_filter string no 仅在匹配的分支上触发推送事件的钩子
branch_filter_strategy string no 按分支过滤推送事件。可能的值为 wildcard(默认),regexall_branches

测试系统钩子

使用模拟数据执行系统钩子。

POST /hooks/:id
属性 类型 必需 描述
id integer yes 钩子的 ID

示例请求:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks/1"

响应始终是模拟数据:

{
   "project_id" : 1,
   "owner_email" : "example@gitlabhq.com",
   "owner_name" : "Someone",
   "name" : "Ruby",
   "path" : "ruby",
   "event_name" : "project_create"
}

删除系统钩子

删除一个系统钩子。

DELETE /hooks/:id
属性 类型 必需 描述
id integer yes 钩子的 ID

示例请求:

curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks/2"

设置 URL 变量

{{< history >}}

  1. 在 GitLab 15.2 中引入。

{{< /history >}}

PUT /hooks/:hook_id/url_variables/:key

支持的属性:

属性 类型 必需 描述
hook_id integer Yes 系统钩子的 ID。
key string Yes URL 变量的键。
value string Yes URL 变量的值。

成功时,该端点返回响应代码 204 No Content

删除 URL 变量

{{< history >}}

  1. 在 GitLab 15.2 中引入。

{{< /history >}}

DELETE /hooks/:hook_id/url_variables/:key

支持的属性:

属性 类型 必需 描述
hook_id integer Yes 系统钩子的 ID。
key string Yes URL 变量的键。

成功时,该端点返回响应代码 204 No Content