Help us learn about your current experience with the documentation. Take the survey.

实例级 CI/CD 变量 API

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab Self-Managed, GitLab Dedicated

使用此 API 与实例的 CI/CD 变量 进行交互。

列出所有实例变量

获取所有实例级变量的列表。使用 pageper_page 分页 参数来控制结果的分页。

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
    }
]

显示实例变量详情

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

GET /admin/ci/variables/:key
属性 类型 必需 描述
key string 变量的 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
}

创建实例变量

创建新的实例级变量。

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

POST /admin/ci/variables
属性 类型 必需 描述
key string 变量的 key。最多 255 个字符,只允许 A-Za-z0-9_
value string 变量的 value。最多 10,000 个字符。
description string 变量的描述。最多 255 个字符。
masked boolean 变量是否被掩码。
protected boolean 变量是否受保护。
raw boolean 变量是否可扩展。
variable_type string 变量的类型。可用类型为: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
}

更新实例变量

更新实例级变量。

PUT /admin/ci/variables/:key
属性 类型 必需 描述
description string 变量的描述。最多 255 个字符。
key string 变量的 key。最多 255 个字符,只允许 A-Za-z0-9_
masked boolean 变量是否被掩码。
protected boolean 变量是否受保护。
raw boolean 变量是否可扩展。
value string 变量的 value。最多 10,000 个字符。
variable_type string 变量的类型。可用类型为: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 变量的 key
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/admin/ci/variables/VARIABLE_1"