Help us learn about your current experience with the documentation. Take the survey.
Pages API
- 版本:Free, Premium, Ultimate
- 产品形态:GitLab.com, GitLab Self-Managed, GitLab Dedicated
用于管理 GitLab Pages 的端点。
使用这些端点需要先启用 GitLab Pages 功能。了解更多关于管理和使用该功能的信息。
取消发布 Pages
前提条件:
- 您必须至少拥有该项目的 Maintainer 角色。
移除 Pages。
DELETE /projects/:id/pages| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径 |
curl --request 'DELETE' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/2/pages"获取项目的 Pages 设置
前提条件:
- 您必须至少拥有该项目的 Maintainer 角色。
列出项目的 Pages 设置。
GET /projects/:id/pages支持的属性:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径 |
如果成功,将返回 200 状态码以及以下响应属性:
| 属性 | 类型 | 描述 |
|---|---|---|
url |
string | 用于访问此项目 Pages 的 URL。 |
is_unique_domain_enabled |
boolean | 是否启用了唯一域名。 |
force_https |
boolean | 如果项目设置为强制使用 HTTPS,则为 true。 |
deployments[] |
array | 当前活跃部署的列表。 |
primary_domain |
string | 用于将所有 Pages 请求重定向到的主域名。在 GitLab 17.8 中引入。 |
deployments[] 属性 |
类型 | 描述 |
|---|---|---|
created_at |
date | 部署的创建日期。 |
url |
string | 此部署的 URL。 |
path_prefix |
string | 使用并行部署时,此部署的路径前缀。 |
root_directory |
string | 根目录。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/2/pages"示例响应:
{
"url": "http://html-root-4160ce5f0e9a6c90ccb02755b7fc80f5a2a09ffbb1976cf80b653.pages.gdk.test:3010",
"is_unique_domain_enabled": true,
"force_https": false,
"deployments": [
{
"created_at": "2024-01-05T18:58:14.916Z",
"url": "http://html-root-4160ce5f0e9a6c90ccb02755b7fc80f5a2a09ffbb1976cf80b653.pages.gdk.test:3010/",
"path_prefix": "",
"root_directory": null
},
{
"created_at": "2024-01-05T18:58:46.042Z",
"url": "http://html-root-4160ce5f0e9a6c90ccb02755b7fc80f5a2a09ffbb1976cf80b653.pages.gdk.test:3010/mr3",
"path_prefix": "mr3",
"root_directory": null
}
],
"primary_domain": null
}更新项目的 Pages 设置
前提条件:
- 您必须至少拥有该项目的 Maintainer 角色。
更新项目的 Pages 设置。
PATCH /projects/:id/pages支持的属性:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径 |
pages_unique_domain_enabled |
boolean | 否 | 是否使用唯一域名 |
pages_https_only |
boolean | 否 | 是否强制使用 HTTPS |
pages_primary_domain |
string | 否 | 从现有分配的域名中设置主域名,以将所有 Pages 请求重定向到该域名。在 GitLab 17.8 中引入。 |
如果成功,将返回 200 状态码以及以下响应属性:
| 属性 | 类型 | 描述 |
|---|---|---|
url |
string | 用于访问此项目 Pages 的 URL。 |
is_unique_domain_enabled |
boolean | 是否启用了唯一域名。 |
force_https |
boolean | 如果项目设置为强制使用 HTTPS,则为 true。 |
deployments[] |
array | 当前活跃部署的列表。 |
primary_domain |
string | 用于将所有 Pages 请求重定向到的主域名。在 GitLab 17.8 中引入。 |
deployments[] 属性 |
类型 | 描述 |
|---|---|---|
created_at |
date | 部署的创建日期。 |
url |
string | 此部署的 URL。 |
path_prefix |
string | 使用并行部署时,此部署的路径前缀。 |
root_directory |
string | 根目录。 |
示例请求:
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/:id/pages" \
--form 'pages_unique_domain_enabled=true' \
--form 'pages_https_only=true' \
--form 'pages_primary_domain=https://custom.example.com'示例响应:
{
"url": "http://html-root-4160ce5f0e9a6c90ccb02755b7fc80f5a2a09ffbb1976cf80b653.pages.gdk.test:3010",
"is_unique_domain_enabled": true,
"force_https": false,
"deployments": [
{
"created_at": "2024-01-05T18:58:14.916Z",
"url": "http://html-root-4160ce5f0e9a6c90ccb02755b7fc80f5a2a09ffbb1976cf80b653.pages.gdk.test:3010/",
"path_prefix": "",
"root_directory": null
},
{
"created_at": "2024-01-05T18:58:46.042Z",
"url": "http://html-root-4160ce5f0e9a6c90ccb02755b7fc80f5a2a09ffbb1976cf80b653.pages.gdk.test:3010/mr3",
"path_prefix": "mr3",
"root_directory": null
}
],
"primary_domain": null
}