Use this API to manage CI/CD variables for a project, a group, or an instance.

Managing project variables requires the Maintainer role for the project. Managing group variables requires the Owner role for the group. Managing instance variables requires administrator access.

List all instance variables

GET /api/v4/admin/ci/variables

Lists all instance-level variables. Use the page and per_page pagination parameters to control the pagination of results.

Parameters

NameTypeDescription
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—

Create a new instance-level variable

POST /api/v4/admin/ci/variables

FE version

Request body (application/json)

PropertyTypeDescription
descriptionStringThe description of the variable
key
Required
StringThe key of the variable. Max 255 characters
maskedBooleanWhether the variable is masked
protectedBooleanWhether the variable is protected
rawBooleanWhether the variable will be expanded
value
Required
StringThe value of a variable
variable_typeStringThe type of a variable. Available types are: env_var (default) and file
Allowed values: env_var, file

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesCiVariable
400400 Bad Request—

Retrieve instance variable details

GET /api/v4/admin/ci/variables/{key}

Retrieves details of a specified instance-level variable.

Parameters

NameTypeDescription
key
Path, required
StringKey of the instance variable. Must be 255 characters or fewer and contain only A-Z, a-z, 0-9, and _

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Instance Variable Not Found—

Update an instance-level variable

PUT /api/v4/admin/ci/variables/{key}

FE version

Parameters

NameTypeDescription
key
Path, required
StringThe key of a variable

Request body (application/json)

PropertyTypeDescription
descriptionStringThe description of the variable
maskedBooleanWhether the variable is masked
protectedBooleanWhether the variable is protected
rawBooleanWhether the variable will be expanded
valueStringThe value of a variable
variable_typeStringThe type of a variable. Available types are: env_var (default) and file
Allowed values: env_var, file

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Instance Variable Not Found—

Delete an existing instance-level variable

DELETE /api/v4/admin/ci/variables/{key}

FE version

Parameters

NameTypeDescription
key
Path, required
StringThe key of a variable

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Instance Variable Not Found—

List all group variables

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

Lists all variables for a specified group. Use the page and per_page pagination parameters to control the pagination of results.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the group
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Not Found—

Create a group variable

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

Creates a group variable.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the group

Request body (application/json)

PropertyTypeDescription
descriptionStringDescription of the variable. Limited to 255 characters
environment_scopeStringThe environment scope of a variable
key
Required
StringKey of the group variable. Must be 255 characters or fewer and contain only A-Z, a-z, 0-9, and _
maskedBooleanIf true, the variable is masked
masked_and_hiddenBooleanIf true, the variable is masked and hidden
protectedBooleanIf true, the variable is protected
rawBooleanIf true, the variable is treated as a raw string. If false, the value is expanded
value
Required
StringValue of the variable
variable_typeStringThe type of the variable
Allowed values: env_var, file
Default: env_var

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesCiVariable
400400 Bad Request—
404Not Found—

Retrieve details of a group variable

GET /api/v4/groups/{id}/variables/{key}

Retrieves details of a specified group variable. If there are multiple variables with the same key, use filter to select the correct environment_scope.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the group
key
Path, required
StringKey of the group variable. Must be 255 characters or fewer and contain only A-Z, a-z, 0-9, and _

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Group Variable Not Found—

Update a group variable

PUT /api/v4/groups/{id}/variables/{key}

Updates a specified group variable. If there are multiple variables with the same key, use filter to select the correct environment_scope.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the group
key
Path, required
StringKey of the group variable. Must be 255 characters or fewer and contain only A-Z, a-z, 0-9, and _

Request body (application/json)

PropertyTypeDescription
descriptionStringDescription of the variable. Limited to 255 characters
environment_scopeStringThe environment scope of a variable
maskedBooleanIf true, the variable is masked
protectedBooleanIf true, the variable is protected
rawBooleanIf true, the variable is treated as a raw string. If false, the value is expanded
valueStringValue of the variable
variable_typeStringThe type of the variable. Default: env_var
Allowed values: env_var, file

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400400 Bad Request—
404Group Variable Not Found—

Delete a group variable

DELETE /api/v4/groups/{id}/variables/{key}

Deletes a specified group variable. If there are multiple variables with the same key, use filter to select the correct environment_scope.

Parameters

NameTypeDescription
id
Path, required
StringID or URL-encoded path of the group
key
Path, required
StringKey of the group variable. Must be 255 characters or fewer and contain only A-Z, a-z, 0-9, and _

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Group Variable Not Found—

List all project variables

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

Lists all variables for a project. Use the page and per_page pagination parameters to control the pagination of results.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Not Found—

Create a variable

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

Creates a variable. If a variable with the same key already exists, the variable must have a different environment_scope. Otherwise, GitLab returns a message similar to: VARIABLE_NAME has already been taken.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project

Request body (application/json)

PropertyTypeDescription
descriptionStringDescription of the variable. Limited to 255 characters
environment_scopeStringEnvironment scope of the variable. Defaults to *
key
Required
StringKey of the project variable. Must be 255 characters or fewer and contain only A-Z, a-z, 0-9, and _
maskedBooleanIf true, the variable is masked
masked_and_hiddenBooleanIf true, the variable is masked and hidden. Introduced in GitLab 17.4
protectedBooleanIf true, the variable is protected
rawBooleanIf true, the variable is treated as a raw string. If false, the value is expanded
value
Required
StringValue of the variable
variable_typeStringThe type of the variable
Allowed values: env_var, file
Default: env_var

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesCiVariable
400400 Bad Request—
404Not Found—

Retrieve a single variable

GET /api/v4/projects/{id}/variables/{key}

Retrieves details of a specified variable. If there are multiple variables with the same key, use filter to select the correct environment_scope.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
key
Path, required
StringKey of the project variable. Must be 255 characters or fewer and contain only A-Z, a-z, 0-9, and _
filter
Query
ObjectFilter results when multiple variables share the same key
filter[environment_scope]
Query
StringEnvironment scope of the variable

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Variable Not Found—

Update a variable

PUT /api/v4/projects/{id}/variables/{key}

Updates a project variable. If there are multiple variables with the same key, use filter to select the correct environment_scope.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
key
Path, required
StringKey of the project variable. Must be 255 characters or fewer and contain only A-Z, a-z, 0-9, and _

Request body (application/json)

PropertyTypeDescription
descriptionStringDescription of the variable. Limited to 255 characters
environment_scopeStringEnvironment scope of the variable
filterObjectFilter results when multiple variables share the same key
filter.environment_scopeStringEnvironment scope of the variable
maskedBooleanIf true, the variable is masked
protectedBooleanIf true, the variable is protected
rawBooleanIf true, the variable is treated as a raw string. If false, the value is expanded
valueStringValue of the variable
variable_typeStringThe type of the variable. Default: env_var
Allowed values: env_var, file

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Variable Not Found—

Delete a variable

DELETE /api/v4/projects/{id}/variables/{key}

Deletes a project variable. If there are multiple variables with the same key, use filter to select the correct environment_scope.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
key
Path, required
StringKey of the project variable. Must be 255 characters or fewer and contain only A-Z, a-z, 0-9, and _
filter
Query
ObjectFilter results when multiple variables share the same key
filter[environment_scope]
Query
StringEnvironment scope of the variable

Responses

CodeDescriptionSchema
200OKAPIEntitiesCiVariable
400Bad Request—
404Variable Not Found—

Schemas

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

APIEntitiesCiVariable

PropertyTypeDescription
descriptionStringExample: This variable is being used for ...
environment_scopeStringExample: *
hiddenBoolean—
keyStringExample: TEST_VARIABLE_1
maskedBoolean—
protectedBoolean—
rawBoolean—
valueStringExample: TEST_1
variable_typeStringExample: env_var