Group-level Variables API

原文:https://docs.gitlab.com/ee/api/group_level_variables.html

Group-level Variables API

在 GitLab 9.5 中引入

List group variables

获取组变量的列表.

  1. GET /groups/:id/variables
Attribute Type required Description
id integer/string yes 经过身份验证的用户拥有的组的 ID 或URL 编码的路径
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/variables"
  1. [ { "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

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

  1. GET /groups/:id/variables/:key
Attribute Type required Description
id integer/string yes 经过身份验证的用户拥有的组的 ID 或URL 编码的路径
key string yes 变量的key
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/variables/TEST_VARIABLE_1"
  1. { "key": "TEST_VARIABLE_1", "variable_type": "env_var", "value": "TEST_1", "protected": false, "masked": false }

Create variable

创建一个新变量.

  1. POST /groups/:id/variables
Attribute Type required Description
id integer/string yes 经过身份验证的用户拥有的组的 ID 或URL 编码的路径
key string yes 变量的key ; 不得超过 255 个字符; 仅允许AZaz0-9_
value string yes 变量的value
variable_type string no 变量的类型. 可用类型为: env_var (默认)和file
protected boolean no 变量是否受保护
masked boolean no 变量是否被屏蔽
  1. 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"
  1. { "key": "NEW_VARIABLE", "value": "new value", "variable_type": "env_var", "protected": false, "masked": false }

Update variable

更新组的变量.

  1. 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 变量是否被屏蔽
  1. curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/variables/NEW_VARIABLE" --form "value=updated value"
  1. { "key": "NEW_VARIABLE", "value": "updated value", "variable_type": "env_var", "protected": true, "masked": true }

Remove variable

删除组的变量.

  1. DELETE /groups/:id/variables/:key
Attribute Type required Description
id integer/string yes 经过身份验证的用户拥有的组的 ID 或URL 编码的路径
key string yes 变量的key
  1. curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/variables/VARIABLE_1"