{{< details >}}

  • Tier: 基础版, 专业版, 旗舰版
  • Offering: GitLab Self-Managed, GitLab Dedicated

{{< /details >}}

列出所有实例变量

{{< history >}}

  • description 参数引入于极狐GitLab 16.8。

{{< /history >}}

获取所有实例级变量的列表。

GET /admin/ci/variables
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/admin/ci/variables"
[
    {
        "key": "TEST_VARIABLE_1",
        "description": null,
        "variable_type": "env_var",
        "value": "TEST_1",
        "protected": false,
        "masked": false,
        "raw": false
    },
    {
        "key": "TEST_VARIABLE_2",
        "description": null,
        "variable_type": "env_var",
        "value": "TEST_2",
        "protected": false,
        "masked": false,
        "raw": false
    }
]

显示实例变量详情

{{< history >}}

  • description 参数引入于极狐GitLab 16.8。

{{< /history >}}

获取特定实例级变量的详细信息。

GET /admin/ci/variables/:key
属性 类型 必需 描述
key string Yes 变量的 key
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/admin/ci/variables/TEST_VARIABLE_1"
{
    "key": "TEST_VARIABLE_1",
    "description": null,
    "variable_type": "env_var",
    "value": "TEST_1",
    "protected": false,
    "masked": false,
    "raw": false
}

创建实例变量

{{< history >}}

  • description 参数引入于极狐GitLab 16.8。

{{< /history >}}

创建一个新的实例级变量。

最大实例级变量数可以更改。

POST /admin/ci/variables
属性 类型 必需 描述
key string Yes 变量的 key。最多 255 个字符,只允许 A-Za-z0-9_
value string Yes 变量的 value。最多 10,000 个字符。
description string No 变量的描述。最多 255 个字符。
masked boolean No 变量是否被遮蔽。
protected boolean No 变量是否被保护。
raw boolean No 变量是否可扩展。
variable_type string No 变量的类型。可用类型为:env_var(默认)和 file
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
     "https://gitlab.example.com/api/v4/admin/ci/variables" --form "key=NEW_VARIABLE" --form "value=new value"
{
    "key": "NEW_VARIABLE",
    "description": null,
    "value": "new value",
    "variable_type": "env_var",
    "protected": false,
    "masked": false,
    "raw": false
}

更新实例变量

{{< history >}}

  • description 参数引入于极狐GitLab 16.8。

{{< /history >}}

更新实例级变量。

PUT /admin/ci/variables/:key
属性 类型 必需 描述
description string No 变量的描述。最多 255 个字符。
key string Yes 变量的 key。最多 255 个字符,只允许 A-Za-z0-9_
masked boolean No 变量是否被遮蔽。
protected boolean No 变量是否被保护。
raw boolean No 变量是否可扩展。
value string Yes 变量的 value。最多 10,000 个字符。
variable_type string No 变量的类型。可用类型为:env_var(默认)和 file
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" \
     "https://gitlab.example.com/api/v4/admin/ci/variables/NEW_VARIABLE" --form "value=updated value"
{
    "key": "NEW_VARIABLE",
    "description": null,
    "value": "updated value",
    "variable_type": "env_var",
    "protected": true,
    "masked": true,
    "raw": true
}

移除实例变量

移除一个实例级变量。

DELETE /admin/ci/variables/:key
属性 类型 必需 描述
key string Yes 变量的 key
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/admin/ci/variables/VARIABLE_1"