正式なドキュメントは英語版であり、この日本語訳はAI支援翻訳により作成された参考用のものです。日本語訳の一部の内容は人間によるレビューがまだ行われていないため、翻訳のタイミングにより英語版との間に差異が生じることがあります。最新かつ正確な情報については、英語版をご参照ください。

機能フラグAPI

  • プラン: Free、Premium、Ultimate
  • 提供形態: GitLab.com、GitLab Self-Managed、GitLab Dedicated

このAPIを使用して、GitLabの機能フラグを操作します。

前提要件:

  • デベロッパーロール以上が必要です。

プロジェクトの機能フラグを一覧表示します

リクエストされたプロジェクトのすべての機能フラグを取得します。

GET /projects/:id/feature_flags

結果のページネーションを制御するには、pageおよびper_page ページネーションパラメータを使用します。

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
scope文字列いいえ機能フラグの状態(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

結果のページネーションを制御するには、pageおよびper_page ページネーションパラメータを使用します。

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
feature_flag_name文字列はい機能フラグの名前。
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整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
name文字列はい機能フラグの名前。
version文字列はい非推奨機能フラグのバージョン。new_version_flagである必要があります。レガシー機能フラグを作成するには、省略します。
description文字列いいえ機能フラグの説明。
activeブール値いいえフラグのアクティブな状態。デフォルトはtrueです。
strategies戦略JSONオブジェクトの配列いいえ機能フラグの戦略
strategies:nameJSONいいえ戦略名。defaultgradualRolloutUserIduserWithId、またはgitlabUserListを指定できます。GitLab 13.5以降では、flexibleRolloutを指定できます。
strategies:parametersJSONいいえ戦略パラメータ。
strategies:scopesJSONいいえ戦略のスコープ。
strategies:scopes:environment_scope文字列いいえスコープの環境スコープ。
strategies:user_list_id整数または文字列いいえ機能フラグユーザーリストの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整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
feature_flag_name文字列はい機能フラグの現在の名前。
description文字列いいえ機能フラグの説明。
activeブール値いいえフラグのアクティブな状態。
name文字列いいえ機能フラグの新しい名前。
strategies戦略JSONオブジェクトの配列いいえ機能フラグの戦略
strategies:idJSONいいえ機能フラグ戦略ID。
strategies:nameJSONいいえ戦略名。
strategies:_destroyブール値いいえtrueの場合、戦略を削除します。
strategies:parametersJSONいいえ戦略パラメータ。
strategies:scopesJSONいいえ戦略のスコープ。
strategies:scopes:idJSONいいえ環境スコープID。
strategies:scopes:environment_scope文字列いいえスコープの環境スコープ。
strategies:scopes:_destroyブール値いいえtrueの場合、スコープを削除します。
strategies:user_list_id整数または文字列いいえ機能フラグユーザーリストの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整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
feature_flag_name文字列はい機能フラグの名前。
curl --header "PRIVATE-TOKEN: <your_access_token>" --request DELETE "https://gitlab.example.com/api/v4/projects/1/feature_flags/awesome_feature"