群组级受保护环境 API
引入于极狐GitLab 14.0。部署在
group_level_protected_environments
标志后,默认禁用。功能标记
group_level_protected_environments
移除于极狐GitLab 14.3。普遍可用于极狐GitLab 14.3。
您还可以阅读群组级受保护环境。
有效访问级别
ProtectedEnvironment::DeployAccessLevel::ALLOWED_ACCESS_LEVELS
中定义了访问级别。级别为:
30 => Developer access
40 => Maintainer access
60 => Admin access
列出群组级受保护环境
获取群组的受保护环境的列表。
GET /groups/:id/protected_environments
参数 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id
| integer/string | yes | 授权用户维护的 ID 或 URL 编码的群组路径 |
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/protected_environments/"
响应示例:
[
{
"name":"production",
"deploy_access_levels":[
{
"access_level": 40,
"access_level_description": "Maintainers",
"user_id": null,
"group_id": null
}
],
"required_approval_count": 0
}
]
获取单个受保护环境
获取单个受保护环境。
GET /groups/:id/protected_environments/:name
参数 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id
| integer/string | yes | 授权用户维护的 ID 或 URL 编码的群组路径 |
name
| string | yes | 受保护环境的部署级别。是 production 、staging 、testing 、development 或 other 之一。阅读更多关于部署级别的内容
|
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/protected_environments/production"
响应示例:
{
"name":"production",
"deploy_access_levels":[
{
"access_level":40,
"access_level_description":"Maintainers",
"user_id":null,
"group_id":null
}
],
"required_approval_count": 0
}
保护环境
保护单个环境。
POST /groups/:id/protected_environments
参数 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id
| integer/string | yes | 授权用户维护的 ID 或 URL 编码的群组路径 |
name
| string | yes | 受保护环境的部署级别。是 production 、staging 、testing 、development 或 other 之一。阅读更多关于部署级别的内容
|
deploy_access_levels
| array | yes | 允许部署的访问级别的阵列,通过哈希描述。是 user_id 、group_id 或 access_level 之一。它们各自采用 {user_id: integer} 、{group_id: integer} 或 {access_level: integer} 的形式
|
required_approval_count
| integer | no | 部署到环境所需的批准的数量。是部署批准的一部分,暂时不可用 |
approval_rules
| array | no | 允许批准的访问级别的阵列,通过哈希描述。是 user_id 、group_id 或 access_level 之一。它们各自采用 {user_id: integer} 、{group_id: integer} 或 {access_level: integer} 的形式。您也可以使用 required_approvals 字段指定特定实体所需的批准的数量。详情请参见多个批准规则
|
可分配的 user_id
是属于特定群组的拥有维护者角色(及以上)的用户。
可分配的 group_id
是特定群组下面的子群组。
curl --header 'Content-Type: application/json' --request POST --data '{"name": "production", "deploy_access_levels": [{"group_id": 9899826}]}' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/22034114/protected_environments"
响应示例:
{
"name":"production",
"deploy_access_levels":[
{
"access_level": 40,
"access_level_description": "protected-access-group",
"user_id": null,
"group_id": 9899826
}
],
"required_approval_count": 0
}
不保护环境
不保护特定的受保护环境。
DELETE /groups/:id/protected_environments/:name
参数 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id
| integer/string | yes | 授权用户维护的 ID 或 URL 编码的群组路径 |
name
| string | yes | 受保护环境的部署级别。是 production 、staging 、testing 、development 或 other 之一。阅读更多关于部署级别的内容
|
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/protected_environments/staging"
响应应该返回 200 码。