Use this API to manage protected environments for a project, and protected environments for a group for a group.

The project endpoints require CI/CD to be turned on for the project. If CI/CD is turned off, requests return 403 Forbidden, even for users who otherwise have permission to manage protected environments.

List protected environments for a group

GET /api/v4/groups/{id}/protected_environments

Lists the protected environments configured for a group.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
Example: 11
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesProtectedEnvironment
400Bad Request—
404Not Found—

Create a protected environment for a group

POST /api/v4/groups/{id}/protected_environments

Creates a protected environment and its nested configuration for a group.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
Example: 11

Request body (application/json)

PropertyTypeDescription
approval_rules_attributesArray of objects—
approval_rules_attributes[]._destroyBoolean—
approval_rules_attributes[].access_levelIntegerExample: 40
approval_rules_attributes[].group_idIntegerExample: 3
approval_rules_attributes[].group_inheritance_typeIntegerAllowed values: 0, 1
approval_rules_attributes[].idIntegerExample: 1
approval_rules_attributes[].required_approvalsIntegerExample: 1
approval_rules_attributes[].user_idIntegerExample: 2
deploy_access_levels_attributesArray of objects—
deploy_access_levels_attributes[]._destroyBoolean—
deploy_access_levels_attributes[].access_levelIntegerExample: 40
deploy_access_levels_attributes[].group_idIntegerExample: 3
deploy_access_levels_attributes[].group_inheritance_typeIntegerAllowed values: 0, 1
deploy_access_levels_attributes[].idIntegerExample: 1
deploy_access_levels_attributes[].user_idIntegerExample: 2
name
Required
StringAllowed values: production, staging, testing, development, other
Minimum length: 1
required_approval_countIntegerExample: 0

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesProtectedEnvironment
400Bad Request—
404Not Found—

Retrieve a protected environment for a group

GET /api/v4/groups/{id}/protected_environments/{name}

Retrieves a protected environment configured for a group.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
Example: 11
name
Path, required
StringAllowed values: production, staging, testing, development, other
Minimum length: 1
Example: production

Responses

CodeDescriptionSchema
200OKAPIEntitiesProtectedEnvironment
400Bad Request—
404Not Found—

Update nested protected environment configuration for a group

PUT /api/v4/groups/{id}/protected_environments/{name}

Updates nested configuration without changing the protected environment name.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
Example: 11
name
Path, required
StringAllowed values: production, staging, testing, development, other
Minimum length: 1
Example: production

Request body (application/json)

PropertyTypeDescription
approval_rules_attributesArray of objects—
approval_rules_attributes[]._destroyBoolean—
approval_rules_attributes[].access_levelIntegerExample: 40
approval_rules_attributes[].group_idIntegerExample: 3
approval_rules_attributes[].group_inheritance_typeIntegerAllowed values: 0, 1
approval_rules_attributes[].idIntegerExample: 1
approval_rules_attributes[].required_approvalsIntegerExample: 1
approval_rules_attributes[].user_idIntegerExample: 2
deploy_access_levels_attributesArray of objects—
deploy_access_levels_attributes[]._destroyBoolean—
deploy_access_levels_attributes[].access_levelIntegerExample: 40
deploy_access_levels_attributes[].group_idIntegerExample: 3
deploy_access_levels_attributes[].group_inheritance_typeIntegerAllowed values: 0, 1
deploy_access_levels_attributes[].idIntegerExample: 1
deploy_access_levels_attributes[].user_idIntegerExample: 2
required_approval_countIntegerExample: 0

Responses

CodeDescriptionSchema
200OKAPIEntitiesProtectedEnvironment
400Bad Request—
404Not Found—

Delete a protected environment from a group

DELETE /api/v4/groups/{id}/protected_environments/{name}

Deletes a protected environment and its nested configuration from a group.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the group
Example: 11
name
Path, required
StringAllowed values: production, staging, testing, development, other
Minimum length: 1
Example: production

Responses

CodeDescriptionSchema
204No Content—
400Bad Request—
404Not Found—

List protected environments for a project

GET /api/v4/projects/{id}/protected_environments

Lists the protected environments configured for a project.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
Example: 11
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesProtectedEnvironment
400Bad Request—
404Not Found—

Create a protected environment for a project

POST /api/v4/projects/{id}/protected_environments

Creates a protected environment and its nested configuration for a project.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
Example: 11

Request body (application/json)

PropertyTypeDescription
approval_rules_attributesArray of objects—
approval_rules_attributes[]._destroyBoolean—
approval_rules_attributes[].access_levelIntegerExample: 40
approval_rules_attributes[].group_idIntegerExample: 3
approval_rules_attributes[].group_inheritance_typeIntegerAllowed values: 0, 1
approval_rules_attributes[].idIntegerExample: 1
approval_rules_attributes[].required_approvalsIntegerExample: 1
approval_rules_attributes[].user_idIntegerExample: 2
deploy_access_levels_attributesArray of objects—
deploy_access_levels_attributes[]._destroyBoolean—
deploy_access_levels_attributes[].access_levelIntegerExample: 40
deploy_access_levels_attributes[].group_idIntegerExample: 3
deploy_access_levels_attributes[].group_inheritance_typeIntegerAllowed values: 0, 1
deploy_access_levels_attributes[].idIntegerExample: 1
deploy_access_levels_attributes[].user_idIntegerExample: 2
name
Required
StringExample: production
required_approval_countIntegerExample: 0

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesProtectedEnvironment
400Bad Request—
404Not Found—

List inherited protected environments for a project

GET /api/v4/projects/{id}/protected_environments/inherited

Lists protected environments inherited from the project group hierarchy.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
Example: 11
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesInheritedProtectedEnvironment
400Bad Request—
404Not Found—

Retrieve a protected environment for a project

GET /api/v4/projects/{id}/protected_environments/{name}

Retrieves a protected environment configured for a project.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
Example: 11
name
Path, required
StringExample: production

Responses

CodeDescriptionSchema
200OKAPIEntitiesProtectedEnvironment
400Bad Request—
404Not Found—

Update nested protected environment configuration for a project

PUT /api/v4/projects/{id}/protected_environments/{name}

Updates nested configuration without changing the protected environment name.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
Example: 11
name
Path, required
StringExample: production

Request body (application/json)

PropertyTypeDescription
approval_rules_attributesArray of objects—
approval_rules_attributes[]._destroyBoolean—
approval_rules_attributes[].access_levelIntegerExample: 40
approval_rules_attributes[].group_idIntegerExample: 3
approval_rules_attributes[].group_inheritance_typeIntegerAllowed values: 0, 1
approval_rules_attributes[].idIntegerExample: 1
approval_rules_attributes[].required_approvalsIntegerExample: 1
approval_rules_attributes[].user_idIntegerExample: 2
deploy_access_levels_attributesArray of objects—
deploy_access_levels_attributes[]._destroyBoolean—
deploy_access_levels_attributes[].access_levelIntegerExample: 40
deploy_access_levels_attributes[].group_idIntegerExample: 3
deploy_access_levels_attributes[].group_inheritance_typeIntegerAllowed values: 0, 1
deploy_access_levels_attributes[].idIntegerExample: 1
deploy_access_levels_attributes[].user_idIntegerExample: 2
required_approval_countIntegerExample: 0

Responses

CodeDescriptionSchema
200OKAPIEntitiesProtectedEnvironment
400Bad Request—
404Not Found—

Delete a protected environment from a project

DELETE /api/v4/projects/{id}/protected_environments/{name}

Deletes a protected environment and its nested configuration from a project.

Parameters

NameTypeDescription
id
Path, required
String or integerThe ID or URL-encoded path of the project
Example: 11
name
Path, required
StringExample: production

Responses

CodeDescriptionSchema
204No Content—
400Bad Request—
404Not Found—

Schemas

Objects returned by the operations above and objects nested in their request bodies.

APIEntitiesInheritedProtectedEnvironment

PropertyTypeDescription
approval_rulesArray of APIEntitiesProtectedEnvironmentApprovalRule—
deploy_access_levelsArray of APIEntitiesProtectedEnvironmentAccessLevel—
groupAPIEntitiesProtectedEnvironmentOwnerGroup—
idInteger (int64)Example: 1
nameStringExample: production
required_approval_countIntegerExample: 0

APIEntitiesProtectedEnvironment

PropertyTypeDescription
approval_rulesArray of APIEntitiesProtectedEnvironmentApprovalRule—
deploy_access_levelsArray of APIEntitiesProtectedEnvironmentAccessLevel—
idInteger (int64)Example: 1
nameStringExample: production
required_approval_countIntegerExample: 0

APIEntitiesProtectedEnvironmentAccessLevel

PropertyTypeDescription
access_levelIntegerExample: 40
access_level_descriptionStringExample: Maintainers
group_idInteger (int64)Example: 3
group_inheritance_typeIntegerExample: 0
idInteger (int64)Example: 1
user_idInteger (int64)Example: 2

APIEntitiesProtectedEnvironmentApprovalRule

PropertyTypeDescription
access_levelIntegerExample: 40
access_level_descriptionStringExample: Maintainers
group_idInteger (int64)Example: 3
group_inheritance_typeIntegerExample: 0
idInteger (int64)Example: 1
required_approvalsIntegerExample: 1
user_idInteger (int64)Example: 2

APIEntitiesProtectedEnvironmentOwnerGroup

PropertyTypeDescription
full_nameStringExample: Platform
full_pathStringExample: platform
idInteger (int64)Example: 1
web_pathStringExample: /groups/platform