{{< details >}}
- Tier: 基础版, 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
{{< /details >}}
列出群组变量
获取群组的变量列表。
GET /groups/:id/variables
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 群组的 ID 或 群组的 URL 编码路径 |
curl \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/1/variables"
[
{
"key": "TEST_VARIABLE_1",
"variable_type": "env_var",
"value": "TEST_1",
"protected": false,
"masked": false,
"hidden": false,
"raw": false,
"environment_scope": "*",
"description": null
},
{
"key": "TEST_VARIABLE_2",
"variable_type": "env_var",
"value": "TEST_2",
"protected": false,
"masked": false,
"hidden": false,
"raw": false,
"environment_scope": "*",
"description": null
}
]
显示变量详情
{{< history >}}
-
filter
参数在极狐GitLab 16.9 中引入。
{{< /history >}}
获取群组中特定变量的详细信息。如果有多个具有相同键的变量,使用 filter
选择正确的 environment_scope
。
GET /groups/:id/variables/:key
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 群组的 ID 或 群组的 URL 编码路径 |
key |
string | 是 | 变量的 key
|
filter |
hash | 否 | 可用过滤器: [environment_scope] 。查看 filter 参数详情。 |
curl \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "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,
"hidden": false,
"raw": false,
"environment_scope": "*",
"description": null
}
创建变量
{{< history >}}
-
masked_and_hidden
和hidden
属性在极狐GitLab 17.4 中引入。
{{< /history >}}
创建一个新变量。
POST /groups/:id/variables
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 群组的 ID 或 群组的 URL 编码路径。 |
key |
string | 是 | 变量的 key ;最多不能超过 255 个字符;仅允许 A-Z 、a-z 、0-9 和 _ 。 |
value |
string | 是 | 变量的 value 。 |
description |
string | 否 | 变量的 description ;最多不能超过 255 个字符。默认: null 。 |
environment_scope |
string | 否 | 变量的 环境范围。仅限专业版和旗舰版。 |
masked |
boolean | 否 | 变量是否被掩码。 |
masked_and_hidden |
boolean | 否 | 变量是否被掩码和隐藏。默认: false
|
protected |
boolean | 否 | 变量是否被保护。 |
raw |
boolean | 否 | 变量是否被视为原始字符串。默认: false 。当为 true 时,值中的变量不会被 扩展。 |
variable_type |
string | 否 | 变量的类型。可用类型为: env_var (默认) 和 file 。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "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,
"hidden": false,
"raw": false,
"environment_scope": "*",
"description": null
}
更新变量
{{< history >}}
-
filter
参数在极狐GitLab 16.9 中引入。
{{< /history >}}
更新群组的变量。如果有多个具有相同键的变量,使用 filter
选择正确的 environment_scope
。
PUT /groups/:id/variables/:key
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 群组的 ID 或 群组的 URL 编码路径 |
key |
string | 是 | 变量的 key
|
value |
string | 是 | 变量的 value
|
description |
string | 否 | 变量的描述。默认: null 。在 极狐GitLab 16.2 中引入。 |
environment_scope |
string | 否 | 变量的 环境范围。仅限专业版和旗舰版。 |
filter |
hash | 否 | 可用过滤器: [environment_scope] 。查看 filter 参数详情。 |
masked |
boolean | 否 | 变量是否被掩码 |
protected |
boolean | 否 | 变量是否被保护 |
raw |
boolean | 否 | 变量是否被视为原始字符串。默认: false 。当为 true 时,值中的变量不会被 扩展。 |
variable_type |
string | 否 | 变量的类型。可用类型为: env_var (默认) 和 file
|
curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "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,
"hidden": false,
"raw": true,
"environment_scope": "*",
"description": null
}
移除变量
{{< history >}}
-
filter
参数在极狐GitLab 16.9 中引入。
{{< /history >}}
移除群组的变量。如果有多个具有相同键的变量,使用 filter
选择正确的 environment_scope
。
DELETE /groups/:id/variables/:key
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 群组的 ID 或 群组的 URL 编码路径 |
key |
string | 是 | 变量的 key
|
filter |
hash | 否 | 可用过滤器: [environment_scope] 。查看 filter 参数详情。 |
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/1/variables/VARIABLE_1"
filter
参数
{{< details >}}
- Tier: 专业版, 旗舰版
- Offering: JihuLab.com, 极狐GitLab 私有化部署, 极狐GitLab Dedicated
{{< /details >}}
{{< history >}}
- 在极狐GitLab 16.9 中引入。
{{< /history >}}
当多个变量具有相同的 key
时,GET、PUT 或 DELETE 请求可能会返回:
There are multiple variables with provided parameters. Please use 'filter[environment_scope]'.
使用 filter[environment_scope]
选择与 environment_scope
属性匹配的变量。
例如:
-
GET:
curl \ --globoff \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/groups/1/variables/SCOPED_VARIABLE_1?filter[environment_scope]=production"
-
PUT:
curl --request PUT \ --globoff \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/groups/1/variables/SCOPED_VARIABLE_1?value=scoped-variable-updated-value&environment_scope=production&filter[environment_scope]=production"
-
DELETE:
curl --request DELETE \ --globoff \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/groups/1/variables/SCOPED_VARIABLE_1?filter[environment_scope]=production"