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
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items 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
StringThe key of a variable

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
StringThe ID of a group or URL-encoded path of the group owned by the authenticated user
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items 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
StringThe ID of a group or URL-encoded path of the group owned by the authenticated user

Request body (application/json)

PropertyTypeDescription
descriptionStringThe description of the variable
environment_scopeStringThe environment scope of a variable
key
Required
StringThe ID of a group or URL-encoded path of the group owned by the authenticated user
maskedBooleanWhether the variable is masked
masked_and_hiddenBooleanWhether the variable is masked and hidden
protectedBooleanWhether the variable is protected
rawBooleanWhether the variable will be expanded
value
Required
StringThe value of a variable
variable_typeStringThe type of the variable. Default: env_var
Allowed values: env_var, file

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
StringThe ID of a group or URL-encoded path of the group owned by the authenticated user
key
Path, required
StringThe key of the variable

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
StringThe ID of a group or URL-encoded path of the group owned by the authenticated user
key
Path, required
StringThe key of a variable

Request body (application/json)

PropertyTypeDescription
descriptionStringThe description of the variable
environment_scopeStringThe environment scope of a 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 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
StringThe ID of a group or URL-encoded path of the group owned by the authenticated user
key
Path, required
StringThe key of a variable

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 integerThe ID of a project or URL-encoded NAMESPACE/PROJECT_NAME of the project owned by the authenticated user
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items 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 integerThe ID of a project or URL-encoded NAMESPACE/PROJECT_NAME of the project owned by the authenticated user

Request body (application/json)

PropertyTypeDescription
descriptionStringThe description of the variable
environment_scopeStringThe environment_scope of the variable
key
Required
StringThe key of a variable
maskedBooleanWhether the variable is masked
masked_and_hiddenBooleanWhether the variable is masked and hidden
protectedBooleanWhether the variable is protected
rawBooleanWhether the variable will be expanded
value
Required
StringThe value of a variable
variable_typeStringThe type of the variable. Default: env_var
Allowed values: env_var, file

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 integerThe ID of a project or URL-encoded NAMESPACE/PROJECT_NAME of the project owned by the authenticated user
key
Path, required
StringThe key of a variable
filter
Query
ObjectAvailable filters: [environment_scope]. Example: filter[environment_scope]=production
filter[environment_scope]
Query
StringThe environment scope of a 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 integerThe ID of a project or URL-encoded NAMESPACE/PROJECT_NAME of the project owned by the authenticated user
key
Path, required
StringThe key of a variable

Request body (application/json)

PropertyTypeDescription
descriptionStringThe description of the variable
environment_scopeStringThe environment_scope of a variable
filterObjectAvailable filters: [environment_scope]. Example: filter[environment_scope]=production
filter.environment_scopeStringThe environment scope of a 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 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 integerThe ID of a project or URL-encoded NAMESPACE/PROJECT_NAME of the project owned by the authenticated user
key
Path, required
StringThe key of a variable
filter
Query
ObjectAvailable filters: [environment_scope]. Example: filter[environment_scope]=production
filter[environment_scope]
Query
StringThe environment 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