Help us learn about your current experience with the documentation. Take the survey.
部署令牌 API
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
使用此 API 与部署令牌进行交互。
列出所有部署令牌
- Tier: Free, Premium, Ultimate
- Offering: GitLab Self-Managed, GitLab Dedicated
获取 GitLab 实例中所有部署令牌的列表。此端点需要管理员访问权限。
GET /deploy_tokens参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
active |
boolean | 否 | 按激活状态限制。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/deploy_tokens"示例响应:
[
{
"id": 1,
"name": "MyToken",
"username": "gitlab+deploy-token-1",
"expires_at": "2020-02-14T00:00:00.000Z",
"revoked": false,
"expired": false,
"scopes": [
"read_repository",
"read_registry"
]
}
]项目部署令牌
项目部署令牌 API 端点至少需要项目的维护者角色。
列出项目部署令牌
获取项目的部署令牌列表。
GET /projects/:id/deploy_tokens参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | ID 或项目的 URL 编码路径。 |
active |
boolean | 否 | 按激活状态限制。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/deploy_tokens"示例响应:
[
{
"id": 1,
"name": "MyToken",
"username": "gitlab+deploy-token-1",
"expires_at": "2020-02-14T00:00:00.000Z",
"revoked": false,
"expired": false,
"scopes": [
"read_repository",
"read_registry"
]
}
]获取项目部署令牌
通过 ID 获取单个项目的部署令牌。
GET /projects/:id/deploy_tokens/:token_id参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | ID 或项目的 URL 编码路径 |
token_id |
integer | 是 | 部署令牌的 ID |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/deploy_tokens/1"示例响应:
{
"id": 1,
"name": "MyToken",
"username": "gitlab+deploy-token-1",
"expires_at": "2020-02-14T00:00:00.000Z",
"revoked": false,
"expired": false,
"scopes": [
"read_repository",
"read_registry"
]
}创建项目部署令牌
为项目创建新的部署令牌。
POST /projects/:id/deploy_tokens参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | ID 或项目的 URL 编码路径 |
name |
string | 是 | 新部署令牌的名称 |
scopes |
array of strings | 是 | 指示部署令牌的范围。必须至少是 read_repository、read_registry、write_registry、read_package_registry、write_package_registry、read_virtual_registry 或 write_virtual_registry 中的一个。 |
expires_at |
datetime | 否 | 部署令牌的到期日期。如果未提供值,则不会过期。期望使用 ISO 8601 格式(2019-03-15T08:00:00Z) |
username |
string | 否 | 部署令牌的用户名。默认为 gitlab+deploy-token-{n} |
示例请求:
curl --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/"示例响应:
{
"id": 1,
"name": "My deploy token",
"username": "custom-user",
"expires_at": "2021-01-01T00:00:00.000Z",
"token": "jMRvtPNxrn3crTAGukpZ",
"revoked": false,
"expired": false,
"scopes": [
"read_repository"
]
}删除项目部署令牌
从项目中移除部署令牌。
DELETE /projects/:id/deploy_tokens/:token_id参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | ID 或项目的 URL 编码路径 |
token_id |
integer | 是 | 部署令牌的 ID |
示例请求:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/deploy_tokens/13"组部署令牌
至少具有组维护者角色的用户可以列出组部署令牌。只有组所有者可以创建和删除组部署令牌。
列出组部署令牌
获取组的部署令牌列表
GET /groups/:id/deploy_tokens参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | ID 或组的 URL 编码路径。 |
active |
boolean | 否 | 按激活状态限制。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url"https://gitlab.example.com/api/v4/groups/1/deploy_tokens"示例响应:
[
{
"id": 1,
"name": "MyToken",
"username": "gitlab+deploy-token-1",
"expires_at": "2020-02-14T00:00:00.000Z",
"revoked": false,
"expired": false,
"scopes": [
"read_repository",
"read_registry"
]
}
]获取组部署令牌
通过 ID 获取单个组的部署令牌。
GET /groups/:id/deploy_tokens/:token_id参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | ID 或组的 URL 编码路径 |
token_id |
integer | 是 | 部署令牌的 ID |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/1/deploy_tokens/1"示例响应:
{
"id": 1,
"name": "MyToken",
"username": "gitlab+deploy-token-1",
"expires_at": "2020-02-14T00:00:00.000Z",
"revoked": false,
"expired": false,
"scopes": [
"read_repository",
"read_registry"
]
}创建组部署令牌
为组创建新的部署令牌。
POST /groups/:id/deploy_tokens参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | ID 或组的 URL 编码路径 |
name |
string | 是 | 新部署令牌的名称 |
scopes |
array of strings | 是 | 指示部署令牌的范围。必须至少是 read_repository、read_registry、write_registry、read_package_registry 或 write_package_registry 中的一个。 |
expires_at |
datetime | 否 | 部署令牌的到期日期。如果未提供值,则不会过期。期望使用 ISO 8601 格式(2019-03-15T08:00:00Z) |
username |
string | 否 | 部署令牌的用户名。默认为 gitlab+deploy-token-{n} |
示例请求:
curl --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/"示例响应:
{
"id": 1,
"name": "My deploy token",
"username": "custom-user",
"expires_at": "2021-01-01T00:00:00.000Z",
"token": "jMRvtPNxrn3crTAGukpZ",
"revoked": false,
"expired": false,
"scopes": [
"read_registry"
]
}删除组部署令牌
从组中移除部署令牌。
DELETE /groups/:id/deploy_tokens/:token_id参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | ID 或组的 URL 编码路径 |
token_id |
integer | 是 | 部署令牌的 ID |
示例请求:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/5/deploy_tokens/13"