Group-level Variables API
原文:https://docs.gitlab.com/ee/api/group_level_variables.html
Group-level Variables API
在 GitLab 9.5 中引入
List group variables
获取组变量的列表.
GET /groups/:id/variables 
| Attribute | Type | required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 经过身份验证的用户拥有的组的 ID 或URL 编码的路径 | 
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
获取组特定变量的详细信息.
GET /groups/:id/variables/:key 
| Attribute | Type | required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 经过身份验证的用户拥有的组的 ID 或URL 编码的路径 | 
 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
创建一个新变量.
POST /groups/:id/variables 
| Attribute | Type | required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 经过身份验证的用户拥有的组的 ID 或URL 编码的路径 | 
 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
更新组的变量.
PUT /groups/:id/variables/:key 
| Attribute | Type | required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 经过身份验证的用户拥有的组的 ID 或URL 编码的路径 | 
 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
删除组的变量.
DELETE /groups/:id/variables/:key 
| Attribute | Type | required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 经过身份验证的用户拥有的组的 ID 或URL 编码的路径 | 
 key  | 
string | yes |  变量的key | 
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/variables/VARIABLE_1"