project_level_variables.md 3.76 KB
Newer Older
Shinya Maeda's avatar
Shinya Maeda committed
1
# Project-level Variables  API
Tomasz Maczukin's avatar
Tomasz Maczukin committed
2 3 4

## List project variables

Shinya Maeda's avatar
Shinya Maeda committed
5
Get list of a project's variables.
Tomasz Maczukin's avatar
Tomasz Maczukin committed
6 7 8 9 10

```
GET /projects/:id/variables
```

11 12
| Attribute | Type    | required | Description         |
|-----------|---------|----------|---------------------|
13
| `id`      | integer/string | yes      | The ID of a project or [urlencoded NAMESPACE/PROJECT_NAME of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
14 15

```
16
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables"
17
```
Tomasz Maczukin's avatar
Tomasz Maczukin committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

```json
[
    {
        "key": "TEST_VARIABLE_1",
        "value": "TEST_1"
    },
    {
        "key": "TEST_VARIABLE_2",
        "value": "TEST_2"
    }
]
```

## Show variable details

Shinya Maeda's avatar
Shinya Maeda committed
34
Get the details of a project's specific variable.
Tomasz Maczukin's avatar
Tomasz Maczukin committed
35 36 37 38 39

```
GET /projects/:id/variables/:key
```

40 41
| Attribute | Type    | required | Description           |
|-----------|---------|----------|-----------------------|
42
| `id`      | integer/string | yes      | The ID of a project or [urlencoded NAMESPACE/PROJECT_NAME of the project](README.md#namespaced-path-encoding) owned by the authenticated user   |
43
| `key`     | string  | yes      | The `key` of a variable |
44 45

```
46
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables/TEST_VARIABLE_1"
47 48
```

Tomasz Maczukin's avatar
Tomasz Maczukin committed
49 50 51 52 53 54 55 56 57
```json
{
    "key": "TEST_VARIABLE_1",
    "value": "TEST_1"
}
```

## Create variable

Shinya Maeda's avatar
Shinya Maeda committed
58
Create a new variable.
Tomasz Maczukin's avatar
Tomasz Maczukin committed
59 60 61 62 63

```
POST /projects/:id/variables
```

64 65 66 67 68 69
| Attribute   | Type    | required | Description           |
|-------------|---------|----------|-----------------------|
| `id`        | integer/string | yes      | The ID of a project or [urlencoded NAMESPACE/PROJECT_NAME of the project](README.md#namespaced-path-encoding) owned by the authenticated user   |
| `key`       | string  | yes      | The `key` of a variable; must have no more than 255 characters; only `A-Z`, `a-z`, `0-9`, and `_` are allowed |
| `value`     | string  | yes      | The `value` of a variable |
| `protected` | boolean | no       | Whether the variable is protected |
70 71

```
72
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables" --form "key=NEW_VARIABLE" --form "value=new value"
73 74
```

Tomasz Maczukin's avatar
Tomasz Maczukin committed
75 76 77
```json
{
    "key": "NEW_VARIABLE",
78 79
    "value": "new value",
    "protected": false
Tomasz Maczukin's avatar
Tomasz Maczukin committed
80 81 82 83 84
}
```

## Update variable

Shinya Maeda's avatar
Shinya Maeda committed
85
Update a project's variable.
Tomasz Maczukin's avatar
Tomasz Maczukin committed
86 87 88 89 90

```
PUT /projects/:id/variables/:key
```

91 92 93 94 95 96
| Attribute   | Type    | required | Description             |
|-------------|---------|----------|-------------------------|
| `id`        | integer/string | yes      | The ID of a project or [urlencoded NAMESPACE/PROJECT_NAME of the project](README.md#namespaced-path-encoding) owned by the authenticated user     |
| `key`       | string  | yes      | The `key` of a variable   |
| `value`     | string  | yes      | The `value` of a variable |
| `protected` | boolean | no       | Whether the variable is protected |
97 98

```
99
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables/NEW_VARIABLE" --form "value=updated value"
100 101
```

Tomasz Maczukin's avatar
Tomasz Maczukin committed
102 103 104
```json
{
    "key": "NEW_VARIABLE",
105 106
    "value": "updated value",
    "protected": true
Tomasz Maczukin's avatar
Tomasz Maczukin committed
107 108 109 110 111
}
```

## Remove variable

Shinya Maeda's avatar
Shinya Maeda committed
112
Remove a project's variable.
Tomasz Maczukin's avatar
Tomasz Maczukin committed
113 114 115 116 117

```
DELETE /projects/:id/variables/:key
```

118 119
| Attribute | Type    | required | Description             |
|-----------|---------|----------|-------------------------|
120
| `id`      | integer/string | yes      | The ID of a project or [urlencoded NAMESPACE/PROJECT_NAME of the project](README.md#namespaced-path-encoding) owned by the authenticated user     |
121
| `key`     | string  | yes      | The `key` of a variable |
122 123

```
124
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables/VARIABLE_1"
125
```