群组级别变量 API

引入于极狐GitLab 9.5。

列出群组变量

获取群组变量列表。

GET /groups/:id/variables
参数 类型 是否必需 描述
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,
    "raw": false,
    "environment_scope": "*"
  },
  {
    "key": "TEST_VARIABLE_2",
    "variable_type": "env_var",
    "value": "TEST_2",
    "protected": false,
    "masked": false,
    "raw": false,
    "environment_scope": "*"
  }
]

显示变量详细信息

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

GET /groups/:id/variables/:key
参数 类型 是否必需 描述
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,
  "raw": false,
  "environment_scope": "*"
}

创建变量

创建新变量。

POST /groups/:id/variables
参数 类型 是否必需 描述
id integer/string yes 授权用户拥有的群组 ID 或 URL 编码的群组路径
key string yes 变量的 key;不能超过 255 个字符,只允许 A-Za-z0-9_
value string yes 变量的 value
variable_type string no 变量的类型。可用类型为 env_var(默认)和 file
protected boolean no 变量是否受保护
masked boolean no 变量是否隐藏
raw boolean no 变量是否可扩展
environment_scope string 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,
  "raw": false,
  "environment_scope": "*"
}

更新变量

更新群组变量。

PUT /groups/:id/variables/:key
参数 类型 是否必需 描述
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 变量是否隐藏
raw boolean no 变量是否可扩展
environment_scope string 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,
  "raw": true,
  "environment_scope": "*"
}

移除变量

移除群组的变量。

DELETE /groups/:id/variables/:key
参数 类型 是否必需 描述
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"