379.md 4.3 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
# Group-level Variables API

> 原文:[https://docs.gitlab.com/ee/api/group_level_variables.html](https://docs.gitlab.com/ee/api/group_level_variables.html)

*   [List group variables](#list-group-variables)
*   [Show variable details](#show-variable-details)
*   [Create variable](#create-variable)
*   [Update variable](#update-variable)
*   [Remove variable](#remove-variable)

# Group-level Variables API[](#group-level-variables-api "Permalink")

在 GitLab 9.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/34519)

## List group variables[](#list-group-variables "Permalink")

获取组变量的列表.

```
GET /groups/:id/variables 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有的组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/variables" 
```

```
[  {  "key":  "TEST_VARIABLE_1",  "variable_type":  "env_var",  "value":  "TEST_1",  "protected":  false,  "masked":  false  },  {  "key":  "TEST_VARIABLE_2",  "variable_type":  "env_var",  "value":  "TEST_2",  "protected":  false,  "masked":  false  }  ] 
```

## Show variable details[](#show-variable-details "Permalink")

获取组特定变量的详细信息.

```
GET /groups/:id/variables/:key 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有的组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `key` | string | yes | 变量的`key` |

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

```
{  "key":  "TEST_VARIABLE_1",  "variable_type":  "env_var",  "value":  "TEST_1",  "protected":  false,  "masked":  false  } 
```

## Create variable[](#create-variable "Permalink")

创建一个新变量.

```
POST /groups/:id/variables 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有的组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `key` | string | yes | 变量的`key` ; 不得超过 255 个字符; 仅允许`AZ``az``0-9``_` |
| `value` | string | yes | 变量的`value` |
| `variable_type` | string | no | 变量的类型. 可用类型为: `env_var` (默认)和`file` |
| `protected` | boolean | no | 变量是否受保护 |
| `masked` | boolean | no | 变量是否被屏蔽 |

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

```
{  "key":  "NEW_VARIABLE",  "value":  "new value",  "variable_type":  "env_var",  "protected":  false,  "masked":  false  } 
```

## Update variable[](#update-variable "Permalink")

更新组的变量.

```
PUT /groups/:id/variables/:key 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有的组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `key` | string | yes | 变量的`key` |
| `value` | string | yes | 变量的`value` |
| `variable_type` | string | no | 变量的类型. 可用类型为: `env_var` (默认)和`file` |
| `protected` | boolean | no | 变量是否受保护 |
| `masked` | boolean | no | 变量是否被屏蔽 |

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

```
{  "key":  "NEW_VARIABLE",  "value":  "updated value",  "variable_type":  "env_var",  "protected":  true,  "masked":  true  } 
```

## Remove variable[](#remove-variable "Permalink")

删除组的变量.

```
DELETE /groups/:id/variables/:key 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有的组的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `key` | string | yes | 变量的`key` |

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