Skip to content

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.

id
required
One of:
string

The ID of a project or URL-encoded NAMESPACE/PROJECT_NAME of the project owned by the authenticated user

Media type application/json
object
key
required

The key of a variable

string
nullable
value
required

The value of a variable

string
nullable
protected

Whether the variable is protected

boolean
nullable
masked

Whether the variable is masked

boolean
nullable
masked_and_hidden

Whether the variable is masked and hidden

boolean
nullable
raw

Whether the variable will be expanded

boolean
nullable
variable_type

The type of the variable. Default: env_var

string
nullable
Allowed values: env_var file
environment_scope

The environment_scope of the variable

string
nullable
description

The description of the variable

string
nullable

Created

Media type application/json
object
variable_type
string
key
string
value
string
hidden
boolean
protected
boolean
masked
boolean
raw
boolean
environment_scope
string
description
string
Example
{
"variable_type": "env_var",
"key": "TEST_VARIABLE_1",
"value": "TEST_1",
"environment_scope": "*",
"description": "This variable is being used for ..."
}

400 Bad Request

Not Found