{{< details >}}
- Tier: 基础版, 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
{{< /details >}}
{{< history >}}
- 在极狐GitLab 17.8 中,新增了参数
auto_stop_setting
。 - 对于使用极狐GitLab CI/CD 作业令牌认证的支持引入于极狐GitLab 16.2。
{{< /history >}}
列出环境
获取给定项目的所有环境。
GET /projects/:id/environments
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL-encoded 路径。 |
name |
string | 否 | 返回具有此名称的环境。与 search 互斥。 |
search |
string | 否 | 返回符合搜索条件的环境列表。与 name 互斥。必须至少有 3 个字符长。 |
states |
string | 否 | 列出符合特定状态的所有环境。接受的值:available ,stopping 或 stopped 。 如果没有给定状态值,则返回所有环境。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/environments?name=review%2Ffix-foo"
示例响应:
[
{
"id": 1,
"name": "review/fix-foo",
"slug": "review-fix-foo-dfjre3",
"description": "This is review environment",
"external_url": "https://review-fix-foo-dfjre3.gitlab.example.com",
"state": "available",
"tier": "development",
"created_at": "2019-05-25T18:55:13.252Z",
"updated_at": "2019-05-27T18:55:13.252Z",
"enable_advanced_logs_querying": false,
"logs_api_path": "/project/-/logs/k8s.json?environment_name=review%2Ffix-foo",
"auto_stop_at": "2019-06-03T18:55:13.252Z",
"kubernetes_namespace": "flux-system",
"flux_resource_path": "HelmRelease/flux-system",
"auto_stop_setting": "always"
}
]
获取特定环境
GET /projects/:id/environments/:environment_id
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL-encoded path。 |
environment_id |
integer | 是 | 环境的 ID。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/environments/1"
响应示例:
{
"id": 1,
"name": "review/fix-foo",
"slug": "review-fix-foo-dfjre3",
"description": "This is review environment",
"external_url": "https://review-fix-foo-dfjre3.gitlab.example.com",
"state": "available",
"tier": "development",
"created_at": "2019-05-25T18:55:13.252Z",
"updated_at": "2019-05-27T18:55:13.252Z",
"enable_advanced_logs_querying": false,
"logs_api_path": "/project/-/logs/k8s.json?environment_name=review%2Ffix-foo",
"auto_stop_at": "2019-06-03T18:55:13.252Z",
"last_deployment": {
"id": 100,
"iid": 34,
"ref": "fdroid",
"sha": "416d8ea11849050d3d1f5104cf8cf51053e790ab",
"created_at": "2019-03-25T18:55:13.252Z",
"status": "success",
"user": {
"id": 1,
"name": "Administrator",
"state": "active",
"username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://localhost:3000/root"
},
"deployable": {
"id": 710,
"status": "success",
"stage": "deploy",
"name": "staging",
"ref": "fdroid",
"tag": false,
"coverage": null,
"created_at": "2019-03-25T18:55:13.215Z",
"started_at": "2019-03-25T12:54:50.082Z",
"finished_at": "2019-03-25T18:55:13.216Z",
"duration": 21623.13423,
"project": {
"ci_job_token_scope_enabled": false
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.dev/root",
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"skype": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": null
},
"commit": {
"id": "416d8ea11849050d3d1f5104cf8cf51053e790ab",
"short_id": "416d8ea1",
"created_at": "2016-01-02T15:39:18.000Z",
"parent_ids": [
"e9a4449c95c64358840902508fc827f1a2eab7df"
],
"title": "Removed fabric to fix #40",
"message": "Removed fabric to fix #40\n",
"author_name": "Administrator",
"author_email": "admin@example.com",
"authored_date": "2016-01-02T15:39:18.000Z",
"committer_name": "Administrator",
"committer_email": "admin@example.com",
"committed_date": "2016-01-02T15:39:18.000Z"
},
"pipeline": {
"id": 34,
"sha": "416d8ea11849050d3d1f5104cf8cf51053e790ab",
"ref": "fdroid",
"status": "success",
"web_url": "http://localhost:3000/Commit451/lab-coat/pipelines/34"
},
"web_url": "http://localhost:3000/Commit451/lab-coat/-/jobs/710",
"artifacts": [
{
"file_type": "trace",
"size": 1305,
"filename": "job.log",
"file_format": null
}
],
"runner": null,
"artifacts_expire_at": null
}
},
"cluster_agent": {
"id": 1,
"name": "agent-1",
"config_project": {
"id": 20,
"description": "",
"name": "test",
"name_with_namespace": "Administrator / test",
"path": "test",
"path_with_namespace": "root/test",
"created_at": "2022-03-20T20:42:40.221Z"
},
"created_at": "2022-04-20T20:42:40.221Z",
"created_by_user_id": 42
},
"kubernetes_namespace": "flux-system",
"flux_resource_path": "HelmRelease/flux-system",
"auto_stop_setting": "always"
}
创建新环境
使用给定的名称和 external_url
创建一个新的环境。如果环境创建成功,返回 201
,参数错误返回 400
。
POST /projects/:id/environments
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL-encoded path。 |
name |
string | 是 | 环境的名称。 |
description |
string | 否 | 环境的描述。 |
external_url |
string | 否 | 该环境的链接。 |
tier |
string | 否 | 新环境的层级。允许的值为 production ,staging ,testing ,development 和 other 。 |
cluster_agent_id |
integer | 否 | 要与此环境关联的集群代理。 |
kubernetes_namespace |
string | 否 | 要与此环境关联的 Kubernetes 命名空间。 |
flux_resource_path |
string | 否 | 要与此环境关联的 Flux 资源路径。必须是完整的资源路径。例如,helm.toolkit.fluxcd.io/v2/namespaces/gitlab-agent/helmreleases/gitlab-agent 。 |
auto_stop_setting |
string | 否 | 环境的自动停止设置。允许的值为 always 或 with_action 。 |
curl --data "name=deploy&external_url=https://deploy.gitlab.example.com" \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/environments"
示例响应:
{
"id": 1,
"name": "deploy",
"slug": "deploy",
"description": null,
"external_url": "https://deploy.gitlab.example.com",
"state": "available",
"tier": "production",
"created_at": "2019-05-25T18:55:13.252Z",
"updated_at": "2019-05-27T18:55:13.252Z",
"kubernetes_namespace": "flux-system",
"flux_resource_path": "HelmRelease/flux-system",
"auto_stop_setting": "always"
}
更新现有环境
{{< history >}}
- Parameter
name
removed in 极狐GitLab 16.0.
{{< /history >}}
更新现有环境的名称和/或 external_url
。如果环境更新成功,返回 200
。在出现错误时,返回状态码 400
。
PUT /projects/:id/environments/:environments_id
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL-encoded path of the project。 |
environment_id |
integer | 是 | 环境的 ID。 |
description |
string | 否 | 环境的描述。 |
external_url |
string | 否 | 新的 external_url 。 |
tier |
string | 否 | 新环境的层级。允许的值为 production ,staging ,testing ,development 和 other 。 |
cluster_agent_id |
integer or null | 否 | 要与此环境关联的集群代理或 null 以移除它。 |
kubernetes_namespace |
string or null | 否 | 要与此环境关联的 Kubernetes 命名空间或 null 以移除它。 |
flux_resource_path |
string or null | 否 | 要与此环境关联的 Flux 资源路径或 null 以移除它。 |
auto_stop_setting |
string or null | 否 | 环境的自动停止设置。允许的值为 always 或 with_action 。 |
curl --request PUT \
--data "external_url=https://staging.gitlab.example.com" \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/environments/1"
示例响应:
{
"id": 1,
"name": "staging",
"slug": "staging",
"description": null,
"external_url": "https://staging.gitlab.example.com",
"state": "available",
"tier": "staging",
"created_at": "2019-05-25T18:55:13.252Z",
"updated_at": "2019-05-27T18:55:13.252Z",
"kubernetes_namespace": "flux-system",
"flux_resource_path": "HelmRelease/flux-system",
"auto_stop_setting": "always"
}
删除环境
如果环境成功删除,返回 204
,如果环境不存在,返回 404
。环境必须先停止,否则请求返回 403
。
DELETE /projects/:id/environments/:environment_id
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL-encoded path。 |
environment_id |
integer | 是 | 环境的 ID。 |
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/environments/1"
删除多个已停止的审查应用
它计划删除多个已经被停止并且在审查应用文件夹中的环境。实际删除是在执行后的 1 周后进行的。默认情况下,它只删除 30 天或更久的环境。您可以使用 before
参数更改此默认设置。
DELETE /projects/:id/environments/review_apps
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL-encoded path。 |
before |
datetime | 否 | 可以删除的环境的日期。默认为 30 天前。以 ISO 8601 格式 (YYYY-MM-DDTHH:MM:SSZ ) 为预期。 |
limit |
integer | 否 | 要删除的环境的最大数量。默认为 100。 |
dry_run |
boolean | 否 | 出于安全原因,默认为 true 。它执行一个不进行实际删除的干运行。设置为 false 以实际删除环境。 |
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/environments/review_apps"
示例响应:
{
"scheduled_entries": [
{
"id": 387,
"name": "review/023f1bce01229c686a73",
"slug": "review-023f1bce01-3uxznk",
"external_url": null
},
{
"id": 388,
"name": "review/85d4c26a388348d3c4c0",
"slug": "review-85d4c26a38-5giw1c",
"external_url": null
}
],
"unprocessable_entries": []
}
停止环境
如果环境成功停止,返回 200
,如果环境不存在,返回 404
。
POST /projects/:id/environments/:environment_id/stop
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL-encoded path。 |
environment_id |
integer | 是 | 环境的 ID。 |
force |
boolean | 否 | 在不执行 on_stop 操作的情况下强制环境停止。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/environments/1/stop"
示例响应:
{
"id": 1,
"name": "deploy",
"slug": "deploy",
"external_url": "https://deploy.gitlab.example.com",
"state": "stopped",
"created_at": "2019-05-25T18:55:13.252Z",
"updated_at": "2019-05-27T18:55:13.252Z",
"kubernetes_namespace": "flux-system",
"flux_resource_path": "HelmRelease/flux-system",
"auto_stop_setting": "always"
}
停止过时的环境
对在指定日期之前最后修改或部署的所有环境发出停止请求。不包括受保护的环境。如果停止请求成功,返回 200
,如果日期无效,返回 400
。有关环境何时停止的详细信息,请参阅停止环境。
POST /projects/:id/environments/stop_stale
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL-encoded path。 |
before |
date | 是 | 停止在指定日期之前已被修改或部署的环境。以 ISO 8601 格式 (2019-03-15T08:00:00Z ) 为预期。有效输入在 10 年前到 1 周前之间。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/environments/stop_stale?before=10%2F10%2F2021"
示例响应:
{
"message": "Successfully requested stop for all stale environments"
}