グループレベルの保護環境API
- GitLab 14.0 で導入。
 group_level_protected_environmentsフラグの背後でデプロイされ、デフォルトでは無効になっています。- 機能フラグ
 group_level_protected_environmentsはGitLab 14.3で削除されました。- GitLab 14.3で一般的に利用可能。
 
グループレベルの保護環境についてはこちらをご覧ください。
有効なアクセスレベル
アクセス・レベルはProtectedEnvironments::DeployAccessLevel::ALLOWED_ACCESS_LEVELS メソッドで定義されます。現在、これらのレベルが認識されています:
30 => Developer access
40 => Maintainer access
60 => Admin access
グループレベルの保護環境のリスト
グループから保護された環境の一覧を取得します。
GET /groups/:id/protected_environments
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
id | 整数/文字列 | yes | 認証されたユーザーが保持しているグループのIDまたはURLエンコードされたパス。 | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/protected_environments/"
応答例
[
   {
      "name":"production",
      "deploy_access_levels":[
         {
            "id": 12,
            "access_level": 40,
            "access_level_description": "Maintainers",
            "user_id": null,
            "group_id": null
         }
      ],
      "required_approval_count": 0
   }
]
単一の保護された環境を取得します。
単一の保護された環境を取得します。
GET /groups/:id/protected_environments/:name
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
id | 整数/文字列 | yes | 認証されたユーザーが保持しているグループのIDまたはURLエンコードされたパス。 | 
name | 文字列です。 | yes | 保護環境のデプロイ階層。production,staging,testing,development,other のいずれか。デプロイ層の詳細はこちらをご覧ください。 | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/protected_environments/production"
応答例
{
   "name":"production",
   "deploy_access_levels":[
      {
         "id": 12,
         "access_level":40,
         "access_level_description":"Maintainers",
         "user_id":null,
         "group_id":null
      }
   ],
   "required_approval_count": 0
}
単一環境の保護
単一の環境を保護します。
POST /groups/:id/protected_environments
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
id | 整数/文字列 | yes | 認証されたユーザーが保持しているグループのIDまたはURLエンコードされたパス。 | 
name | 文字列です。 | yes | 保護環境のデプロイ階層。production,staging,testing,development,other のいずれか。デプロイ層の詳細はこちらをご覧ください。 | 
deploy_access_levels | アレイ | yes | デプロイに許可されるアクセスレベルの配列で、それぞれがハッシュで記述されています。user_id,group_id,access_level のいずれか。 それぞれ{user_id: integer},{group_id: integer},{access_level: integer} の形式をとります。 | 
required_approval_count | 整数。 | いいえ | この環境へのデプロイに必要な承認者の数。 | 
approval_rules | アレイ | いいえ | ハッシュで記述された、承認者に許可されるアクセスレベルの配列。user_id,group_id,access_level のいずれか。 それぞれ{user_id: integer},{group_id: integer},{access_level: integer} の形式をとります。また、required_approvals フィールドで、指定したエンティティの必要承認者数を指定できます。詳細については、複数承認ルールを参照してください。 | 
割り当て可能なuser_id は、指定されたグループに属し、メンテナーのロール(またはそれ以上)を持つユーザーです。割り当て可能なgroup_id は、指定されたグループ配下のサブグループです。
curl --header 'Content-Type: application/json' --request POST --data '{"name": "production", "deploy_access_levels": [{"group_id": 9899826}]}' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/22034114/protected_environments"
応答例
{
   "name":"production",
   "deploy_access_levels":[
      {
         "id": 12,
         "access_level": 40,
         "access_level_description": "protected-access-group",
         "user_id": null,
         "group_id": 9899826
      }
   ],
   "required_approval_count": 0
}
保護された環境の更新
GitLab 15.4で導入されました。
単一の環境を更新します。
PUT /groups/:id/protected_environments/:name
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
id | 整数/文字列 | yes | 認証されたユーザーが保持しているグループのIDまたはURLエンコードされたパス。 | 
name | 文字列です。 | yes | 保護環境のデプロイ階層。production,staging,testing,development,other のいずれか。デプロイ層の詳細はこちらをご覧ください。 | 
deploy_access_levels | アレイ | いいえ | デプロイに許可されるアクセスレベルの配列で、それぞれがハッシュで記述されています。user_id,group_id,access_level のいずれか。 それぞれ{user_id: integer},{group_id: integer},{access_level: integer} の形式をとります。 | 
required_approval_count | 整数。 | いいえ | この環境へのデプロイに必要な承認者の数。 | 
approval_rules | アレイ | いいえ | ハッシュで記述された、承認者に許可されるアクセスレベルの配列。user_id,group_id,access_level のいずれか。 それぞれ{user_id: integer},{group_id: integer},{access_level: integer} の形式をとります。また、required_approvals フィールドで、指定したエンティティの必要承認者数を指定できます。詳細については、複数承認ルールを参照してください。 | 
更新するには
- 
user_id:更新されたユーザーが、メンテナーのロール(またはそれ以上)を持つ指定されたグループに属していることを確認してください。また、それぞれのハッシュにdeploy_access_levelまたはapproval_ruleのidを渡す必要があります。 - 
group_id:更新されたグループが、この保護環境が属するグループのサブグループであることを確認します。また、それぞれのハッシュでdeploy_access_levelまたはapproval_ruleのidを渡す必要があります。 
削除するには
- 
_destroytrue次の例を参照してください。 
例deploy_access_level レコードの作成
curl --header 'Content-Type: application/json' --request PUT \
     --data '{"deploy_access_levels": [{"group_id": 9899829, access_level: 40}], "required_approval_count": 1}' \
     --header "PRIVATE-TOKEN: <your_access_token>" \
     "https://gitlab.example.com/api/v4/groups/22034114/protected_environments/production"
応答例
{
   "name": "production",
   "deploy_access_levels": [
      {
         "id": 12,
         "access_level": 40,
         "access_level_description": "protected-access-group",
         "user_id": null,
         "group_id": 9899829,
         "group_inheritance_type": 1
      }
   ],
   "required_approval_count": 0
}
例deploy_access_level レコードの更新
curl --header 'Content-Type: application/json' --request PUT \
     --data '{"deploy_access_levels": [{"id": 12, "group_id": 22034120}], "required_approval_count": 2}' \
     --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/22034114/protected_environments/production"
{
   "name": "production",
   "deploy_access_levels": [
      {
         "id": 12,
         "access_level": 40,
         "access_level_description": "protected-access-group",
         "user_id": null,
         "group_id": 22034120,
         "group_inheritance_type": 0
      }
   ],
   "required_approval_count": 2
}
例deploy_access_level レコードの削除
curl --header 'Content-Type: application/json' --request PUT \
     --data '{"deploy_access_levels": [{"id": 12, "_destroy": true}], "required_approval_count": 0}' \
     --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/22034114/protected_environments/production"
応答例
{
   "name": "production",
   "deploy_access_levels": [],
   "required_approval_count": 0
}
例approval_rule レコードの作成
curl --header 'Content-Type: application/json' --request PUT \
     --data '{"approval_rules": [{"group_id": 134, "required_approvals": 1}]}' \
     --header "PRIVATE-TOKEN: <your_access_token>" \
     "https://gitlab.example.com/api/v4/groups/22034114/protected_environments/production"
応答例
{
   "name": "production",
   "approval_rules": [
      {
         "id": 38,
         "user_id": null,
         "group_id": 134,
         "access_level": null,
         "access_level_description": "qa-group",
         "required_approvals": 1,
         "group_inheritance_type": 0
      }
   ]
}
例approval_rule レコードの更新
curl --header 'Content-Type: application/json' --request PUT \
     --data '{"approval_rules": [{"id": 38, "group_id": 135, "required_approvals": 2}]}' \
     --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/22034114/protected_environments/production"
{
   "name": "production",
   "approval_rules": [
      {
         "id": 38,
         "user_id": null,
         "group_id": 135,
         "access_level": null,
         "access_level_description": "security-group",
         "required_approvals": 2,
         "group_inheritance_type": 0
      }
   ]
}
例approval_rule レコードの削除
curl --header 'Content-Type: application/json' --request PUT \
     --data '{"approval_rules": [{"id": 38, "_destroy": true}]}' \
     --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/22034114/protected_environments/production"
応答例
{
   "name": "production",
   "approval_rules": []
}
単一の環境の保護解除
指定された保護された環境の保護を解除します。
DELETE /groups/:id/protected_environments/:name
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
id | 整数/文字列 | yes | 認証されたユーザーが保持しているグループのIDまたはURLエンコードされたパス。 | 
name | 文字列です。 | yes | 保護環境のデプロイ階層。production,staging,testing,development,other のいずれか。デプロイ層の詳細はこちらをご覧ください。 | 
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/5/protected_environments/staging"
応答は 200 コードを返す必要があります。