部署令牌 API
- Tier: 基础版, 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
列出所有部署令牌
- Tier: 基础版, 专业版, 旗舰版
- Offering: 私有化部署
获取整个极狐 GitLab 实例中的所有部署令牌的列表。此端点需要管理员访问权限。
plaintextGET /deploy_tokens
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| active | boolean | No | 通过活动状态进行限制。 |
请求示例:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/deploy_tokens"
响应示例:
json1[ 2 { 3 "id": 1, 4 "name": "MyToken", 5 "username": "gitlab+deploy-token-1", 6 "expires_at": "2020-02-14T00:00:00.000Z", 7 "revoked": false, 8 "expired": false, 9 "scopes": [ 10 "read_repository", 11 "read_registry" 12 ] 13 } 14]
项目部署令牌
项目部署令牌 API 端点至少需要项目的维护者角色。
列出项目部署令牌
获取项目的部署令牌列表。
plaintextGET /projects/:id/deploy_tokens
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或 URL 编码路径。 |
| active | boolean | No | 通过活动状态进行限制。 |
请求示例:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/deploy_tokens"
响应示例:
json1[ 2 { 3 "id": 1, 4 "name": "MyToken", 5 "username": "gitlab+deploy-token-1", 6 "expires_at": "2020-02-14T00:00:00.000Z", 7 "revoked": false, 8 "expired": false, 9 "scopes": [ 10 "read_repository", 11 "read_registry" 12 ] 13 } 14]
获取项目部署令牌
通过 ID 获取单个项目的部署令牌。
plaintextGET /projects/:id/deploy_tokens/:token_id
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或 URL 编码路径。 |
| token_id | integer | Yes | 部署令牌的 ID |
请求示例:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/deploy_tokens/1"
响应示例:
json1{ 2 "id": 1, 3 "name": "MyToken", 4 "username": "gitlab+deploy-token-1", 5 "expires_at": "2020-02-14T00:00:00.000Z", 6 "revoked": false, 7 "expired": false, 8 "scopes": [ 9 "read_repository", 10 "read_registry" 11 ] 12}
创建项目部署令牌
为项目创建一个新的部署令牌。
plaintextPOST /projects/:id/deploy_tokens
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或 URL 编码路径。 |
| name | string | Yes | 新部署令牌的名称 |
| scopes | array of strings | Yes | 指定部署令牌的范围。必须至少包含 read_repository、read_registry、write_registry、read_package_registry 或 write_package_registry 中的一个。 |
| expires_at | datetime | No | 部署令牌的到期日期。如果没有提供值,则不会过期。预期格式为 ISO 8601 (2019-03-15T08:00:00Z) |
| username | string | No | 部署令牌的用户名。默认为 gitlab+deploy-token-{n} |
请求示例:
shellcurl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --header "Content-Type: application/json" \ --data '{"name": "My deploy token", "expires_at": "2021-01-01", "username": "custom-user", "scopes": ["read_repository"]}' \ --url "https://gitlab.example.com/api/v4/projects/5/deploy_tokens/"
响应示例:
json1{ 2 "id": 1, 3 "name": "My deploy token", 4 "username": "custom-user", 5 "expires_at": "2021-01-01T00:00:00.000Z", 6 "token": "jMRvtPNxrn3crTAGukpZ", 7 "revoked": false, 8 "expired": false, 9 "scopes": [ 10 "read_repository" 11 ] 12}
删除项目部署令牌
从项目中移除一个部署令牌。
plaintextDELETE /projects/:id/deploy_tokens/:token_id
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或 URL 编码路径。 |
| token_id | integer | Yes | 部署令牌的 ID |
请求示例:
shellcurl --request DELETE \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/5/deploy_tokens/13"
群组部署令牌
拥有至少群组维护者角色的用户可以列出群组部署令牌。只有群组所有者可以创建和删除群组部署令牌。
列出群组部署令牌
获取群组的部署令牌列表。
plaintextGET /groups/:id/deploy_tokens
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | Yes | 群组的 ID 或 URL 编码路径。 |
| active | boolean | No | 通过活动状态进行限制。 |
请求示例:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/groups/1/deploy_tokens"
响应示例:
json1[ 2 { 3 "id": 1, 4 "name": "MyToken", 5 "username": "gitlab+deploy-token-1", 6 "expires_at": "2020-02-14T00:00:00.000Z", 7 "revoked": false, 8 "expired": false, 9 "scopes": [ 10 "read_repository", 11 "read_registry" 12 ] 13 } 14]
获取群组部署令牌
通过 ID 获取单个群组的部署令牌。
plaintextGET /groups/:id/deploy_tokens/:token_id
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | Yes | 群组的 ID 或 URL 编码路径。 |
| token_id | integer | Yes | 部署令牌的 ID |
请求示例:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/groups/1/deploy_tokens/1"
响应示例:
json1{ 2 "id": 1, 3 "name": "MyToken", 4 "username": "gitlab+deploy-token-1", 5 "expires_at": "2020-02-14T00:00:00.000Z", 6 "revoked": false, 7 "expired": false, 8 "scopes": [ 9 "read_repository", 10 "read_registry" 11 ] 12}
创建群组部署令牌
为群组创建一个新的部署令牌。
plaintextPOST /groups/:id/deploy_tokens
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | Yes | 群组的 ID 或 URL 编码路径。 |
| name | string | Yes | 新部署令牌的名称 |
| scopes | array of strings | Yes | 指定部署令牌的范围。必须至少包含 read_repository、read_registry、write_registry、read_package_registry 或 write_package_registry 中的一个。 |
| expires_at | datetime | No | 部署令牌的到期日期。如果没有提供值,则不会过期。预期格式为 ISO 8601 (2019-03-15T08:00:00Z) |
| username | string | No | 部署令牌的用户名。默认为 gitlab+deploy-token-{n} |
请求示例:
shellcurl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --header "Content-Type: application/json" \ --data '{"name": "My deploy token", "expires_at": "2021-01-01", "username": "custom-user", "scopes": ["read_repository"]}' \ --url "https://gitlab.example.com/api/v4/groups/5/deploy_tokens/"
响应示例:
json1{ 2 "id": 1, 3 "name": "My deploy token", 4 "username": "custom-user", 5 "expires_at": "2021-01-01T00:00:00.000Z", 6 "token": "jMRvtPNxrn3crTAGukpZ", 7 "revoked": false, 8 "expired": false, 9 "scopes": [ 10 "read_registry" 11 ] 12}
删除群组部署令牌
从群组中移除一个部署令牌。
plaintextDELETE /groups/:id/deploy_tokens/:token_id
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | Yes | 群组的 ID 或 URL 编码路径。 |
| token_id | integer | Yes | 部署令牌的 ID |
请求示例:
shellcurl --request DELETE \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/groups/5/deploy_tokens/13"