환경 API
Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
이 API를 사용하여 GitLab 환경과 상호작용합니다. 지정된 프로젝트의 모든 환경을 나열합니다. 프로젝트의 지정된 환경을 조회합니다. 지정된 프로젝트에 대한 환경을 생성합니다. 성공 시 201을 반환하고, 잘못된 파라미터의 경우 400을 반환합니다.
히스토리
- 파라미터
auto_stop_setting이 GitLab 17.8에서 추가되었습니다. - GitLab CI/CD 작업 토큰 인증 지원이 GitLab 16.2에서 도입되었습니다.
이 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"
}
환경 생성#
지정된 프로젝트에 대한 환경을 생성합니다.
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. |
성공 시 201을 반환하고, 잘못된 파라미터의 경우 400을 반환합니다.
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"
}
기존 환경 업데이트#
히스토리
- 파라미터
name이 GitLab 16.0에서 제거되었습니다.
프로젝트의 기존 환경을 업데이트합니다.
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. |
성공 시 200을 반환합니다. 오류 발생 시 400을 반환합니다.
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"
}
환경 삭제#
프로젝트에서 환경을 삭제합니다. 환경은 먼저 중지되어야 합니다.
DELETE /projects/:id/environments/:environment_id
| 속성 | 유형 | 필수 여부 | 설명 |
|---|---|---|---|
id |
정수 또는 문자열 | 예 | 프로젝트의 ID 또는 URL-인코딩된 경로. |
environment_id |
정수 | 예 | 환경의 ID. |
성공 시 204를 반환합니다. 환경이 존재하지 않으면 404를 반환합니다. 환경이 중지되지 않은 경우 403을 반환합니다.
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/environments/1"
중지된 여러 리뷰 앱 삭제#
이미 중지된 리뷰 앱 폴더에 있는 여러 환경의 삭제를 예약합니다. 실제 삭제는 실행 후 1주일 후에 수행됩니다. 기본적으로 30일 이상 된 환경만 삭제합니다.
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": []
}
환경 중지#
실행 중인 환경을 중지합니다.
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"
}
오래된 환경 중지#
지정된 날짜 이전에 마지막으로 수정되거나 배포된 모든 환경을 중지합니다. 보호된 환경은 제외됩니다.
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"
}
