功能标志 API

  • 引入于极狐GitLab 专业版 12.5。

  • 移动到极狐GitLab 基础版 13.5。

用于访问极狐GitLab 功能标志资源的 API。

拥有至少开发者角色的用户可以访问功能标志 API。

功能标志分页

由于 API 结果进行了分页GET 请求一次默认返回 20 个结果。

项目的列表功能标志

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

GET /projects/:id/feature_flags
参数 类型 是否必需 描述
id integer/string yes 项目 ID 或 URL 编码的路径
scope string no 功能标志的状态:enableddisabled
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”。支持于极狐GitLab 13.3 及更高版本。
strategies JSON no 功能标志策略
strategies:name JSON no 标志名称。可以是 defaultgradualRolloutUserIduserWithIdgitlabUserList。在极狐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 标志的活跃状态。支持于极狐GitLab 13.3 及更高版本。
name string no 功能标志的新名称。支持于极狐GitLab 13.3 及更高版本。
strategies JSON no 功能标志策略
strategies:id JSON no 功能标志策略 ID。
strategies:name JSON no 策略名称。
strategies:_destroy boolean no 为真时删除策略。
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 为真时删除范围。
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"