環境API
- プラン: Free、Premium、Ultimate
- 提供形態: GitLab.com、GitLab Self-Managed、GitLab Dedicated
このAPIを使用してGitLab環境を操作します。
環境の一覧表示
特定のプロジェクトのすべての環境を取得します。
GET /projects/:id/environments| 属性 | 型 | 必須 | 説明 |
|---|---|---|---|
id | 整数または文字列 | はい | プロジェクトのIDまたはURLエンコードされたパス。 |
name | 文字列 | いいえ | この名前の環境を返します。searchと相互に排他的です。 |
search | 文字列 | いいえ | 検索条件に一致する環境のリストを返します。nameと相互に排他的です。3文字以上にする必要があります。 |
states | 文字列 | いいえ | 特定のステータスに一致するすべての環境をリストします。指定できる値は、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 | 整数または文字列 | はい | プロジェクトのIDまたはURLエンコードされたパス。 |
environment_id | 整数 | はい | 環境の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": "",
"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 | 整数または文字列 | はい | プロジェクトのIDまたはURLエンコードされたパス。 |
name | 文字列 | はい | 環境の名前。 |
description | 文字列 | いいえ | 環境の説明。 |
external_url | 文字列 | いいえ | この環境にリンクする場所。 |
tier | 文字列 | いいえ | 新しい環境の階層。使用できる値は、production、staging、testing、development、otherです。 |
cluster_agent_id | 整数 | いいえ | この環境に関連付けるクラスタリングエージェント。 |
kubernetes_namespace | 文字列 | いいえ | この環境に関連付けるKubernetesネームスペース。 |
flux_resource_path | 文字列 | いいえ | この環境に関連付けるFluxリソースパス。これはリソースのフルパスでなければなりません。たとえばhelm.toolkit.fluxcd.io/v2/namespaces/gitlab-agent/helmreleases/gitlab-agentなどです。 |
auto_stop_setting | 文字列 | いいえ | 環境の自動停止設定。使用できる値は、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"
}既存の環境を更新
既存の環境の名前またはexternal_urlを更新します。
環境が正常に更新された場合は200を返します。エラーが発生した場合、ステータスコード400が返されます。
PUT /projects/:id/environments/:environments_id| 属性 | 型 | 必須 | 説明 |
|---|---|---|---|
id | 整数または文字列 | はい | プロジェクトのIDまたはURLエンコードされたパス。 |
environment_id | 整数 | はい | 環境のID。 |
description | 文字列 | いいえ | 環境の説明。 |
external_url | 文字列 | いいえ | 新しいexternal_url。 |
tier | 文字列 | いいえ | 新しい環境の階層。使用できる値は、production、staging、testing、development、otherです。 |
cluster_agent_id | 整数またはnull | いいえ | この環境に関連付けるクラスタリングエージェント、または削除する場合はnull。 |
kubernetes_namespace | 文字列またはnull | いいえ | この環境に関連付けるKubernetesネームスペース、または削除する場合はnull。 |
flux_resource_path | 文字列またはnull | いいえ | この環境に関連付けるFluxリソースパス、または削除する場合はnull。 |
auto_stop_setting | 文字列または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 | 整数または文字列 | はい | プロジェクトのIDまたはURLエンコードされたパス。 |
environment_id | 整数 | はい | 環境の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 | 整数または文字列 | はい | プロジェクトのIDまたはURLエンコードされたパス。 |
before | 日時 | いいえ | 環境を削除できる日付(この日付より前の環境)。デフォルトでは、30日前になります。ISO 8601形式(YYYY-MM-DDTHH:MM:SSZ)で指定します。 |
limit | 整数 | いいえ | 削除する環境の最大数。デフォルトは100です。 |
dry_run | ブール値 | いいえ | 安全上の理由から、デフォルトは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 | 整数または文字列 | はい | プロジェクトのIDまたはURLエンコードされたパス。 |
environment_id | 整数 | はい | 環境のID。 |
force | ブール値 | いいえ | 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 | 整数または文字列 | はい | プロジェクトのIDまたはURLエンコードされたパス。 |
before | 日付 | はい | 指定された日付より前に変更またはデプロイされた環境を停止します。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"
}