Feature Flags API

原文:https://docs.gitlab.com/ee/api/feature_flags.html

Feature Flags API

Introduced in GitLab Premium 12.5.

注意:此 API 位于功能标志的后面. 如果您的环境中未启用此标志,则可以使用旧功能标志 API .

用于访问GitLab 功能标记资源的 API.

具有开发者或更高权限的用户可以访问功能标记 API.

Feature Flags pagination

默认情况下,因为 API 结果是分页的 ,所以GET请求一次返回 20 个结果.

List feature flags for a project

获取所请求项目的所有功能标志.

  1. GET /projects/:id/feature_flags
Attribute Type Required Description
id integer/string yes 项目的 ID 或URL 编码的路径 .
scope string no 功能标志的条件,其中之一: enableddisabled .
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/feature_flags"

响应示例:

  1. [ { "name":"merge_train", "description":"This feature is about merge train", "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" } ] } ] }, { "name":"new_live_trace", "description":"This is a new live trace feature", "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" } ] } ] } ]

Get a single feature flag

获取单个功能标志.

  1. GET /projects/:id/feature_flags/:name
Attribute Type Required Description
id integer/string yes 项目的 ID 或URL 编码的路径 .
name string yes The name of the feature flag.
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature

响应示例:

  1. { "name": "awesome_feature", "description": null, "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" } ] } ] }

Create a feature flag

创建一个新的功能标志.

  1. POST /projects/:id/feature_flags
Attribute Type Required Description
id integer/string yes 项目的 ID 或URL 编码的路径 .
name string yes 功能标志的名称.
version string yes 功能标志的版本. 必须是new_version_flag . 省略或设置为legacy_flag即可创建旧版功能标志 .
description string no 功能标志的描述.
strategies JSON no 特征标志策略 .
strategies:name JSON no 策略名称.
strategies:parameters JSON no 策略参数.
strategies:scopes JSON no 策略的范围.
strategies:scopes:environment_scope string no 范围的环境规格.
  1. curl "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. "name": "awesome_feature",
  6. "version": "new_version_flag",
  7. "strategies": [{ "name": "default", "parameters": {}, "scopes": [{ "environment_scope": "production" }] }]
  8. } EOF

响应示例:

  1. { "name": "awesome_feature", "description": null, "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" } ] } ] }

Update a feature flag

更新功能标志.

  1. PUT /projects/:id/feature_flags/:name
Attribute Type Required Description
id integer/string yes 项目的 ID 或URL 编码的路径 .
name string yes 功能标志的名称.
description string no 功能标志的描述.
strategies JSON no 特征标志策略 .
strategies:id JSON no 功能标记策略 ID.
strategies:name JSON no 策略名称.
strategies:parameters JSON no 策略参数.
strategies:scopes JSON no 策略的范围.
strategies:scopes:id JSON no 范围 ID.
strategies:scopes:environment_scope string no 范围的环境规格.
  1. curl "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. "strategies": [{ "name": "gradualRolloutUserId", "parameters": { "groupId": "default", "percentage": "25" }, "scopes": [{ "environment_scope": "staging" }] }]
  6. } EOF

响应示例:

  1. { "name": "awesome_feature", "description": null, "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 a feature flag

删除功能标志.

  1. DELETE /projects/:id/feature_flags/:name
Attribute Type Required Description
id integer/string yes 项目的 ID 或URL 编码的路径 .
name string yes 功能标志的名称.
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" --request DELETE "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"