BigW Consortium Gitlab

build_variables.md 3.58 KB
Newer Older
1
# Build Variables
Tomasz Maczukin committed
2 3 4

## List project variables

5
Get list of a project's build variables.
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: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/variables"
17
```
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

34
Get the details of a project's specific build variable.
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: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/variables/TEST_VARIABLE_1"
47 48
```

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

## Create variable

58
Create a new build variable.
Tomasz Maczukin committed
59 60 61 62 63

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

64 65
| Attribute | Type    | required | Description           |
|-----------|---------|----------|-----------------------|
66
| `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   |
67 68
| `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 |
69 70

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

Tomasz Maczukin committed
74 75 76 77 78 79 80 81 82
```json
{
    "key": "NEW_VARIABLE",
    "value": "new value"
}
```

## Update variable

83
Update a project's build variable.
Tomasz Maczukin committed
84 85 86 87 88

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

89 90
| Attribute | Type    | required | Description             |
|-----------|---------|----------|-------------------------|
91
| `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     |
92 93
| `key`     | string  | yes      | The `key` of a variable   |
| `value`   | string  | yes      | The `value` of a variable |
94 95

```
96
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/variables/NEW_VARIABLE" --form "value=updated value"
97 98
```

Tomasz Maczukin committed
99 100 101 102 103 104 105 106 107
```json
{
    "key": "NEW_VARIABLE",
    "value": "updated value"
}
```

## Remove variable

108
Remove a project's build variable.
Tomasz Maczukin committed
109 110 111 112 113

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

114 115
| Attribute | Type    | required | Description             |
|-----------|---------|----------|-------------------------|
116
| `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     |
117
| `key`     | string  | yes      | The `key` of a variable |
118 119

```
120
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/variables/VARIABLE_1"
121
```