{{< details >}}
- Tier: 基础版, 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
{{< /details >}}
{{< history >}}
- 引入于极狐GitLab专业版 12.5。
- 在极狐GitLab 13.5 中移动至基础版。
{{< /history >}}
用于访问极狐GitLab功能标志资源的 API。
拥有至少开发者角色的用户可以访问功能标志 API。
功能标志分页
默认情况下,GET
请求一次返回 20 个结果,因为 API 结果是分页的。
列出项目的功能标志
获取请求项目的所有功能标志。
GET /projects/:id/feature_flags
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | yes | 项目的 ID 或URL 编码路径。 |
scope |
string | no | 功能标志的条件之一:enabled , disabled 。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/feature_flags"
示例响应:
[
{
"name":"merge_train",
"description":"This feature is about merge train",
"active": true,
"version": "new_version_flag",
"created_at":"2019-11-04T08:13:51.423Z",
"updated_at":"2019-11-04T08:13:51.423Z",
"scopes":[],
"strategies": [
{
"id": 1,
"name": "userWithId",
"parameters": {
"userIds": "user1"
},
"scopes": [
{
"id": 1,
"environment_scope": "production"
}
],
"user_list": null
}
]
},
{
"name":"new_live_trace",
"description":"This is a new live trace feature",
"active": true,
"version": "new_version_flag",
"created_at":"2019-11-04T08:13:10.507Z",
"updated_at":"2019-11-04T08:13:10.507Z",
"scopes":[],
"strategies": [
{
"id": 2,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 2,
"environment_scope": "staging"
}
],
"user_list": null
}
]
},
{
"name":"user_list",
"description":"This feature is about user list",
"active": true,
"version": "new_version_flag",
"created_at":"2019-11-04T08:13:10.507Z",
"updated_at":"2019-11-04T08:13:10.507Z",
"scopes":[],
"strategies": [
{
"id": 2,
"name": "gitlabUserList",
"parameters": {},
"scopes": [
{
"id": 2,
"environment_scope": "staging"
}
],
"user_list": {
"id": 1,
"iid": 1,
"name": "My user list",
"user_xids": "user1,user2,user3"
}
}
]
}
]
获取单个功能标志
获取单个功能标志。
GET /projects/:id/feature_flags/:feature_flag_name
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | yes | 项目的 ID 或URL 编码路径。 |
feature_flag_name |
string | yes | 功能标志的名称。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"
示例响应:
{
"name": "awesome_feature",
"description": null,
"active": true,
"version": "new_version_flag",
"created_at": "2020-05-13T19:56:33.119Z",
"updated_at": "2020-05-13T19:56:33.119Z",
"scopes": [],
"strategies": [
{
"id": 36,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 37,
"environment_scope": "production"
}
],
"user_list": null
}
]
}
创建一个功能标志
创建一个新的功能标志。
POST /projects/:id/feature_flags
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | yes | 项目的 ID 或URL 编码路径。 |
name |
string | yes | 功能标志的名称。 |
version |
string | yes |
已弃用 功能标志的版本。必须是 new_version_flag 。省略以创建传统功能标志。 |
description |
string | no | 功能标志的描述。 |
active |
boolean | no | 标志的活动状态。默认为 true。 |
strategies |
array of strategy JSON objects | no | 功能标志的策略。 |
strategies:name |
JSON | no | 策略名称。可以是 default , gradualRolloutUserId , userWithId , 或 gitlabUserList 。在极狐GitLab 13.5及更高版本中,可以是flexibleRollout 。 |
strategies:parameters |
JSON | no | 策略参数。 |
strategies:scopes |
JSON | no | 策略的范围。 |
strategies:scopes:environment_scope |
string | no | 范围的环境范围。 |
strategies:user_list_id |
integer/string | no | 功能标志用户列表的 ID。如果策略是 gitlabUserList 。 |
curl "https://gitlab.example.com/api/v4/projects/1/feature_flags" \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-type: application/json" \
--data @- << EOF
{
"name": "awesome_feature",
"version": "new_version_flag",
"strategies": [{ "name": "default", "parameters": {}, "scopes": [{ "environment_scope": "production" }] }]
}
EOF
示例响应:
{
"name": "awesome_feature",
"description": null,
"active": true,
"version": "new_version_flag",
"created_at": "2020-05-13T19:56:33.119Z",
"updated_at": "2020-05-13T19:56:33.119Z",
"scopes": [],
"strategies": [
{
"id": 36,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 37,
"environment_scope": "production"
}
]
}
]
}
更新功能标志
更新功能标志。
PUT /projects/:id/feature_flags/:feature_flag_name
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | yes | 项目的 ID 或URL 编码路径。 |
feature_flag_name |
string | yes | 当前功能标志的名称。 |
description |
string | no | 功能标志的描述。 |
active |
boolean | no | 标志的活动状态。 |
name |
string | no | 功能标志的新名称。 |
strategies |
array of strategy JSON objects | no | 功能标志的策略。 |
strategies:id |
JSON | no | 功能标志策略 ID。 |
strategies:name |
JSON | no | 策略名称。 |
strategies:_destroy |
boolean | no | 当为 true 时删除策略。 |
strategies:parameters |
JSON | no | 策略参数。 |
strategies:scopes |
JSON | no | 策略的范围。 |
strategies:scopes:id |
JSON | no | 环境范围 ID。 |
strategies:scopes:environment_scope |
string | no | 范围的环境范围。 |
strategies:scopes:_destroy |
boolean | no | 当为 true 时删除范围。 |
strategies:user_list_id |
integer/string | no | 功能标志用户列表的 ID。如果策略是 gitlabUserList 。 |
curl "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature" \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-type: application/json" \
--data @- << EOF
{
"strategies": [{ "name": "gradualRolloutUserId", "parameters": { "groupId": "default", "percentage": "25" }, "scopes": [{ "environment_scope": "staging" }] }]
}
EOF
示例响应:
{
"name": "awesome_feature",
"description": null,
"active": true,
"version": "new_version_flag",
"created_at": "2020-05-13T20:10:32.891Z",
"updated_at": "2020-05-13T20:10:32.891Z",
"scopes": [],
"strategies": [
{
"id": 38,
"name": "gradualRolloutUserId",
"parameters": {
"groupId": "default",
"percentage": "25"
},
"scopes": [
{
"id": 40,
"environment_scope": "staging"
}
]
},
{
"id": 37,
"name": "default",
"parameters": {},
"scopes": [
{
"id": 39,
"environment_scope": "production"
}
]
}
]
}
删除功能标志
删除功能标志。
DELETE /projects/:id/feature_flags/:feature_flag_name
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | yes | 项目的 ID 或URL 编码路径。 |
feature_flag_name |
string | yes | 功能标志的名称。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" --request DELETE "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"