功能标志 API
- Tier: 基础版, 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
History
- 引入于极狐GitLab专业版 12.5。
- 在极狐GitLab 13.5 中移动至基础版。
用于访问极狐GitLab功能标志资源的 API。
拥有至少开发者角色的用户可以访问功能标志 API。
功能标志分页
默认情况下,GET 请求一次返回 20 个结果,因为 API 结果是分页的。
列出项目的功能标志
获取请求项目的所有功能标志。
plaintextGET /projects/:id/feature_flags
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | yes | 项目的 ID 或URL 编码路径。 |
| scope | string | no | 功能标志的条件之一:enabled, disabled。 |
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/feature_flags"
示例响应:
json1[ 2 { 3 "name":"merge_train", 4 "description":"This feature is about merge train", 5 "active": true, 6 "version": "new_version_flag", 7 "created_at":"2019-11-04T08:13:51.423Z", 8 "updated_at":"2019-11-04T08:13:51.423Z", 9 "scopes":[], 10 "strategies": [ 11 { 12 "id": 1, 13 "name": "userWithId", 14 "parameters": { 15 "userIds": "user1" 16 }, 17 "scopes": [ 18 { 19 "id": 1, 20 "environment_scope": "production" 21 } 22 ], 23 "user_list": null 24 } 25 ] 26 }, 27 { 28 "name":"new_live_trace", 29 "description":"This is a new live trace feature", 30 "active": true, 31 "version": "new_version_flag", 32 "created_at":"2019-11-04T08:13:10.507Z", 33 "updated_at":"2019-11-04T08:13:10.507Z", 34 "scopes":[], 35 "strategies": [ 36 { 37 "id": 2, 38 "name": "default", 39 "parameters": {}, 40 "scopes": [ 41 { 42 "id": 2, 43 "environment_scope": "staging" 44 } 45 ], 46 "user_list": null 47 } 48 ] 49 }, 50 { 51 "name":"user_list", 52 "description":"This feature is about user list", 53 "active": true, 54 "version": "new_version_flag", 55 "created_at":"2019-11-04T08:13:10.507Z", 56 "updated_at":"2019-11-04T08:13:10.507Z", 57 "scopes":[], 58 "strategies": [ 59 { 60 "id": 2, 61 "name": "gitlabUserList", 62 "parameters": {}, 63 "scopes": [ 64 { 65 "id": 2, 66 "environment_scope": "staging" 67 } 68 ], 69 "user_list": { 70 "id": 1, 71 "iid": 1, 72 "name": "My user list", 73 "user_xids": "user1,user2,user3" 74 } 75 } 76 ] 77 } 78]
获取单个功能标志
获取单个功能标志。
plaintextGET /projects/:id/feature_flags/:feature_flag_name
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | yes | 项目的 ID 或URL 编码路径。 |
| feature_flag_name | string | yes | 功能标志的名称。 |
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"
示例响应:
json1{ 2 "name": "awesome_feature", 3 "description": null, 4 "active": true, 5 "version": "new_version_flag", 6 "created_at": "2020-05-13T19:56:33.119Z", 7 "updated_at": "2020-05-13T19:56:33.119Z", 8 "scopes": [], 9 "strategies": [ 10 { 11 "id": 36, 12 "name": "default", 13 "parameters": {}, 14 "scopes": [ 15 { 16 "id": 37, 17 "environment_scope": "production" 18 } 19 ], 20 "user_list": null 21 } 22 ] 23}
创建一个功能标志
创建一个新的功能标志。
plaintextPOST /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。 |
shell1curl "https://gitlab.example.com/api/v4/projects/1/feature_flags" \ 2 --header "PRIVATE-TOKEN: <your_access_token>" \ 3 --header "Content-type: application/json" \ 4 --data @- << EOF 5{ 6 "name": "awesome_feature", 7 "version": "new_version_flag", 8 "strategies": [{ "name": "default", "parameters": {}, "scopes": [{ "environment_scope": "production" }] }] 9} 10EOF
示例响应:
json1{ 2 "name": "awesome_feature", 3 "description": null, 4 "active": true, 5 "version": "new_version_flag", 6 "created_at": "2020-05-13T19:56:33.119Z", 7 "updated_at": "2020-05-13T19:56:33.119Z", 8 "scopes": [], 9 "strategies": [ 10 { 11 "id": 36, 12 "name": "default", 13 "parameters": {}, 14 "scopes": [ 15 { 16 "id": 37, 17 "environment_scope": "production" 18 } 19 ] 20 } 21 ] 22}
更新功能标志
更新功能标志。
plaintextPUT /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。 |
shell1curl "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature" \ 2 --header "PRIVATE-TOKEN: <your_access_token>" \ 3 --header "Content-type: application/json" \ 4 --data @- << EOF 5{ 6 "strategies": [{ "name": "gradualRolloutUserId", "parameters": { "groupId": "default", "percentage": "25" }, "scopes": [{ "environment_scope": "staging" }] }] 7} 8EOF
示例响应:
json1{ 2 "name": "awesome_feature", 3 "description": null, 4 "active": true, 5 "version": "new_version_flag", 6 "created_at": "2020-05-13T20:10:32.891Z", 7 "updated_at": "2020-05-13T20:10:32.891Z", 8 "scopes": [], 9 "strategies": [ 10 { 11 "id": 38, 12 "name": "gradualRolloutUserId", 13 "parameters": { 14 "groupId": "default", 15 "percentage": "25" 16 }, 17 "scopes": [ 18 { 19 "id": 40, 20 "environment_scope": "staging" 21 } 22 ] 23 }, 24 { 25 "id": 37, 26 "name": "default", 27 "parameters": {}, 28 "scopes": [ 29 { 30 "id": 39, 31 "environment_scope": "production" 32 } 33 ] 34 } 35 ] 36}
删除功能标志
删除功能标志。
plaintextDELETE /projects/:id/feature_flags/:feature_flag_name
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | yes | 项目的 ID 或URL 编码路径。 |
| feature_flag_name | string | yes | 功能标志的名称。 |
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" --request DELETE "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"