{{< details >}}
- Tier: 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
{{< /details >}}
您可以使用 REST API 管理项目的 拉取镜像。
获取项目的拉取镜像详情
{{< history >}}
- 在极狐GitLab 15.6 中引入。
- 在极狐GitLab 17.5 中扩展响应,包括镜像配置信息。以下配置设置包括:
enabled
、mirror_trigger_builds
、only_mirror_protected_branches
、mirror_overwrites_diverged_branches
和mirror_branch_regex
。
{{< /history >}}
返回项目的 拉取镜像 的详细信息。
GET /projects/:id/mirror/pull
支持的属性:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer 或 string | 是 | 项目的 ID 或 URL 编码路径。 |
示例请求:
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/:id/mirror/pull"
如果成功,将返回 200 OK
和以下响应属性:
属性 | 类型 | 描述 |
---|---|---|
id |
integer | 镜像配置的唯一标识符。 |
last_error |
string 或 null | 最近的错误信息,如果有则显示。没有错误则为 null 。 |
last_successful_update_at |
string | 最近一次成功镜像更新的时间戳。 |
last_update_at |
string | 最近一次镜像更新尝试的时间戳。 |
last_update_started_at |
string | 最近一次镜像更新进程开始的时间戳。 |
update_status |
string | 镜像更新进程的状态。 |
url |
string | 镜像仓库的 URL。 |
enabled |
boolean | 指示镜像是活跃还是不活跃。 |
mirror_trigger_builds |
boolean | 确定是否应该为镜像更新触发流水线。 |
only_mirror_protected_branches |
boolean 或 null | 指定是否仅镜像受保护的分支。未设置则为 null 。 |
mirror_overwrites_diverged_branches |
boolean | 指示在镜像过程中是否应该覆盖分支。 |
mirror_branch_regex |
string 或 null | 用于过滤要镜像的分支的正则表达式模式。未设置则为 null 。 |
示例响应:
{
"id": 101486,
"last_error": null,
"last_successful_update_at": "2020-01-06T17:32:02.823Z",
"last_update_at": "2020-01-06T17:32:02.823Z",
"last_update_started_at": "2020-01-06T17:31:55.864Z",
"update_status": "finished",
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git",
"enabled": true,
"mirror_trigger_builds": true,
"only_mirror_protected_branches": null,
"mirror_overwrites_diverged_branches": false,
"mirror_branch_regex": null
}
配置项目的拉取镜像
{{< history >}}
- 在极狐GitLab 17.6 中引入。
{{< /history >}}
配置拉取镜像设置。
支持的属性:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
enabled |
boolean | 否 | 设置为 true 时启用项目的拉取镜像。 |
url |
string | 否 | 被镜像的远程仓库的 URL。 |
auth_user |
string | 否 | 用于拉取镜像认证的用户名。 |
auth_password |
string | 否 | 用于拉取镜像认证的密码。 |
mirror_trigger_builds |
boolean | 否 | 设置为 true 时为镜像更新触发流水线。 |
only_mirror_protected_branches |
boolean | 否 | 设置为 true 时仅限镜像受保护的分支。 |
mirror_overwrites_diverged_branches |
boolean | 否 | 覆盖分支。 |
mirror_branch_regex |
String | 否 | 包含正则表达式。仅名称与正则表达式匹配的分支会被镜像。需要 only_mirror_protected_branches 未启用。 |
添加拉取镜像的示例请求:
curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{
"enabled": true,
"url": "https://gitlab.example.com/group/project.git",
"auth_user": "user",
"auth_password": "password"
}' \
--url "https://gitlab.example.com/api/v4/projects/:id/mirror/pull"
移除拉取镜像的示例请求:
curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/:id/mirror/pull" \
--data "enabled=false"
配置项目的拉取镜像(已弃用)
{{< history >}}
- 在极狐GitLab 15.8 中引入字段
mirror_branch_regex
并带有一个标志,名为mirror_only_branches_match_regex
。默认禁用。 - 在极狐GitLab 16.0 中默认启用。
- 在极狐GitLab 16.2 中 GA。移除了功能标志
mirror_only_branches_match_regex
。 - 在极狐GitLab 17.6 中已弃用。
{{< /history >}}
{{< alert type=”warning” >}}
此配置选项在极狐GitLab 17.6 中已弃用,计划在 API 的 v5 中移除。请改用新的配置和端点。此变更为重大变更。
{{< /alert >}}
在使用 API 创建新项目或更新现有项目时配置拉取镜像,如果远程仓库可以公开访问或使用 username:token
认证。如果您的 HTTP 仓库不能公开访问,您可以在 URL 中添加认证信息。例如,https://username:token@gitlab.company.com/group/project.git
其中 token
是启用了 api
范围的个人访问令牌。
支持的属性:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
import_url |
string | 是 | 被镜像的远程仓库的 URL(如有需要可包含 user:token )。 |
mirror |
boolean | 是 | 设置为 true 时启用项目的拉取镜像。 |
mirror_trigger_builds |
boolean | 否 | 设置为 true 时为镜像更新触发流水线。 |
only_mirror_protected_branches |
boolean | 否 | 设置为 true 时仅限镜像受保护的分支。 |
mirror_branch_regex |
String | 否 | 包含正则表达式。仅名称与正则表达式匹配的分支会被镜像。需要 only_mirror_protected_branches 未启用。 |
创建具有拉取镜像的项目的示例:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{
"name": "new_project",
"namespace_id": "1",
"mirror": true,
"import_url": "https://username:token@gitlab.example.com/group/project.git"
}' \
--url "https://gitlab.example.com/api/v4/projects/"
添加拉取镜像的示例:
curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/:id" \
--data "mirror=true&import_url=https://username:token@gitlab.example.com/group/project.git"
移除拉取镜像的示例:
curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/:id" \
--data "mirror=false"
启动项目的拉取镜像过程
启动项目的拉取镜像过程。
POST /projects/:id/mirror/pull
支持的属性:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer 或 string | 是 | 项目的 ID 或 URL 编码路径。 |
示例请求:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/:id/mirror/pull"