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
| Name | Type | Description |
|---|---|---|
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
Create a new instance-level variable
POST /api/v4/admin/ci/variables
FE version
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | The description of the variable |
keyRequired | String | The key of the variable. |
masked | Boolean | Whether the variable is masked |
protected | Boolean | Whether the variable is protected |
raw | Boolean | Whether the variable will be expanded |
valueRequired | String | The value of a variable |
variable_ | String | The type of a variable. Allowed values: env_,file |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | 400 Bad Request | — |
Retrieve instance variable details
GET /api/v4/admin/ci/variables/{key}
Retrieves details of a specified instance-level variable.
Parameters
| Name | Type | Description |
|---|---|---|
keyPath, | String | Key of the instance variable.A-,a-,0-,_ |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Instance Variable Not Found | — |
Update an instance-level variable
PUT /api/v4/admin/ci/variables/{key}
FE version
Parameters
| Name | Type | Description |
|---|---|---|
keyPath, | String | The key of a variable |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | The description of the variable |
masked | Boolean | Whether the variable is masked |
protected | Boolean | Whether the variable is protected |
raw | Boolean | Whether the variable will be expanded |
value | String | The value of a variable |
variable_ | String | The type of a variable. Allowed values: env_,file |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Instance Variable Not Found | — |
Delete an existing instance-level variable
DELETE /api/v4/admin/ci/variables/{key}
FE version
Parameters
| Name | Type | Description |
|---|---|---|
keyPath, | String | The key of a variable |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Instance 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
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not Found | — |
Create a group variable
POST /api/v4/groups/{id}/variables
Creates a group variable.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | Description of the variable. |
environment_ | String | The environment scope of a variable |
keyRequired | String | Key of the group variable.A-,a-,0-,_ |
masked | Boolean | If true, |
masked_ | Boolean | If true, |
protected | Boolean | If true, |
raw | Boolean | If true,false, |
valueRequired | String | Value of the variable |
variable_ | String | The type of the variable Allowed values: env_,fileDefault: env_ |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | 400 Bad Request | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
keyPath, | String | Key of the group variable.A-,a-,0-,_ |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Group 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
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
keyPath, | String | Key of the group variable.A-,a-,0-,_ |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | Description of the variable. |
environment_ | String | The environment scope of a variable |
masked | Boolean | If true, |
protected | Boolean | If true, |
raw | Boolean | If true,false, |
value | String | Value of the variable |
variable_ | String | The type of the variable. Allowed values: env_,file |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | 400 Bad Request | — |
404 | Group 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
| Name | Type | Description |
|---|---|---|
idPath, | String | ID or URL- |
keyPath, | String | Key of the group variable.A-,a-,0-,_ |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Group 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | Description of the variable. |
environment_ | String | Environment scope of the variable.* |
keyRequired | String | Key of the project variable.A-,a-,0-,_ |
masked | Boolean | If true, |
masked_ | Boolean | If true, |
protected | Boolean | If true, |
raw | Boolean | If true,false, |
valueRequired | String | Value of the variable |
variable_ | String | The type of the variable Allowed values: env_,fileDefault: env_ |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
400 | 400 Bad Request | — |
404 | Not 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
keyPath, | String | Key of the project variable.A-,a-,0-,_ |
filterQuery | Object | Filter results when multiple variables share the same key |
filter[environment_Query | String | Environment scope of the variable |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Variable 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
keyPath, | String | Key of the project variable.A-,a-,0-,_ |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
description | String | Description of the variable. |
environment_ | String | Environment scope of the variable |
filter | Object | Filter results when multiple variables share the same key |
filter. | String | Environment scope of the variable |
masked | Boolean | If true, |
protected | Boolean | If true, |
raw | Boolean | If true,false, |
value | String | Value of the variable |
variable_ | String | The type of the variable. Allowed values: env_,file |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Variable 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
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
keyPath, | String | Key of the project variable.A-,a-,0-,_ |
filterQuery | Object | Filter results when multiple variables share the same key |
filter[environment_Query | String | Environment scope of the variable |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Variable Not Found | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesCiVariable
| Property | Type | Description |
|---|---|---|
description | String | Example:This variable is being used for . |
environment_ | String | Example:* |
hidden | Boolean | — |
key | String | Example:TEST_ |
masked | Boolean | — |
protected | Boolean | — |
raw | Boolean | — |
value | String | Example:TEST_ |
variable_ | String | Example:env_ |