배포 API


Tier: Free, Premium, Ultimate
Offering: GitLab.com, Self-managed, GitLab Dedicated

GitLab 16.2에서 소개된 GitLab CI/CD 작업 토큰 인증을 지원합니다.

프로젝트 배포 목록

프로젝트 내 배포 목록을 가져옵니다.

GET /projects/:id/deployments
속성 유형 필수 여부 설명
id integer/string yes 인증된 사용자가 소유한 프로젝트의 ID 또는 URL-encoded path
order_by string no 배포를 id, iid, created_at, updated_at, finished_at, 또는 ref 필드 중 하나로 정렬하여 반환합니다. 기본값은 id입니다.
sort string no 배포를 asc 또는 desc 순서로 정렬하여 반환합니다. 기본값은 asc입니다.
updated_after datetime no 지정된 날짜 이후에 업데이트된 배포를 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 예상됩니다.
updated_before datetime no 지정된 날짜 이전에 업데이트된 배포를 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 예상됩니다.
finished_after datetime no 지정된 날짜 이후에 완료된 배포를 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 예상됩니다.
finished_before datetime no 지정된 날짜 이전에 완료된 배포를 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 예상됩니다.
environment string no 배포를 환경의 이름으로 필터링합니다.
status string no 배포 상태로 필터링합니다. created, running, success, failed, canceled, 또는 blocked 중 하나입니다.
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/deployments"

참고: finished_before 또는 finished_after를 사용할 때 order_byfinished_at로 지정하고, statussuccess여야 합니다.

응답 예시:

[
  {
    "created_at": "2016-08-11T07:36:40.222Z",
    "updated_at": "2016-08-11T07:38:12.414Z",
    "status": "created",
    "deployable": {
      "commit": {
        "author_email": "admin@example.com",
        "author_name": "Administrator",
        "created_at": "2016-08-11T09:36:01.000+02:00",
        "id": "99d03678b90d914dbb1b109132516d71a4a03ea8",
        "message": "Merge branch 'new-title' into 'main'\r\n\r\nUpdate README\r\n\r\n\r\n\r\nSee merge request !1",
        "short_id": "99d03678",
        "title": "Merge branch 'new-title' into 'main'\r"
      },
      "coverage": null,
      "created_at": "2016-08-11T07:36:27.357Z",
      "finished_at": "2016-08-11T07:36:39.851Z",
      "id": 657,
      "name": "deploy",
      "ref": "main",
      "runner": null,
      "stage": "deploy",
      "started_at": null,
      "status": "success",
      "tag": false,
      "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": ""
      },
      "pipeline": {
        "created_at": "2016-08-11T02:12:10.222Z",
        "id": 36,
        "ref": "main",
        "sha": "99d03678b90d914dbb1b109132516d71a4a03ea8",
        "status": "success",
        "updated_at": "2016-08-11T02:12:10.222Z",
        "web_url": "http://gitlab.dev/root/project/pipelines/12"
      }
    },
    "environment": {
      "external_url": "https://about.gitlab.com",
      "id": 9,
      "name": "production"
    },
    "id": 41,
    "iid": 1,
    "ref": "main",
    "sha": "99d03678b90d914dbb1b109132516d71a4a03ea8",
    "user": {
      "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "id": 1,
      "name": "Administrator",
      "state": "active",
      "username": "root",
      "web_url": "http://localhost:3000/root"
    }
  },
  {
    "created_at": "2016-08-11T11:32:35.444Z",
    "updated_at": "2016-08-11T11:34:01.123Z",
    "status": "created",
    "deployable": {
      "commit": {
        "author_email": "admin@example.com",
        "author_name": "Administrator",
        "created_at": "2016-08-11T13:28:26.000+02:00",
        "id": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
        "message": "Merge branch 'rename-readme' into 'main'\r\n\r\nRename README\r\n\r\n\r\n\r\nSee merge request !2",
        "short_id": "a91957a8",
        "title": "Merge branch 'rename-readme' into 'main'\r"
      },
      "coverage": null,
      "created_at": "2016-08-11T11:32:24.456Z",
      "finished_at": "2016-08-11T11:32:35.145Z",
      "id": 664,
      "name": "deploy",
      "ref": "main",
      "runner": null,
      "stage": "deploy",
      "started_at": null,
      "status": "success",
      "tag": false,
      "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": ""
      },
      "pipeline": {
        "created_at": "2016-08-11T07:43:52.143Z",
        "id": 37,
        "ref": "main",
        "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
        "status": "success",
        "updated_at": "2016-08-11T07:43:52.143Z",
        "web_url": "http://gitlab.dev/root/project/pipelines/13"
      }
    },
    "environment": {
      "external_url": "https://about.gitlab.com",
      "id": 9,
      "name": "production"
    },
    "id": 42,
    "iid": 2,
    "ref": "main",
    "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
    "user": {
      "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "id": 1,
      "name": "Administrator",
      "state": "active",
      "username": "root",
      "web_url": "http://localhost:3000/root"
    }
  }
]

특정 배포 가져오기

GET /projects/:id/deployments/:deployment_id
속성 유형 필수 설명
id integer/string yes 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
deployment_id integer yes 배포의 ID
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/deployments/1"

예시 응답:

{
  "id": 42,
  "iid": 2,
  "ref": "main",
  "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
  "created_at": "2016-08-11T11:32:35.444Z",
  "updated_at": "2016-08-11T11:34:01.123Z",
  "status": "success",
  "user": {
    "name": "Administrator",
    "username": "root",
    "id": 1,
    "state": "active",
    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://localhost:3000/root"
  },
  "environment": {
    "id": 9,
    "name": "production",
    "external_url": "https://about.gitlab.com"
  },
  "deployable": {
    "id": 664,
    "status": "success",
    "stage": "deploy",
    "name": "deploy",
    "ref": "main",
    "tag": false,
    "coverage": null,
    "created_at": "2016-08-11T11:32:24.456Z",
    "started_at": null,
    "finished_at": "2016-08-11T11:32:35.145Z",
    "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,
      "skype": "",
      "linkedin": "",
      "twitter": "",
      "website_url": "",
      "organization": ""
    },
    "commit": {
      "id": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
      "short_id": "a91957a8",
      "title": "Merge branch 'rename-readme' into 'main'\r",
      "author_name": "Administrator",
      "author_email": "admin@example.com",
      "created_at": "2016-08-11T13:28:26.000+02:00",
      "message": "Merge branch 'rename-readme' into 'main'\r\n\r\nRename README\r\n\r\n\r\n\r\nSee merge request !2"
    },
    "pipeline": {
      "created_at": "2016-08-11T07:43:52.143Z",
      "id": 42,
      "ref": "main",
      "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
      "status": "success",
      "updated_at": "2016-08-11T07:43:52.143Z",
      "web_url": "http://gitlab.dev/root/project/pipelines/5"
    },
    "runner": null
  }
}

통합 승인 설정이 구성된 경우 GitLab Premium 또는 Ultimate 사용자가 만든 배포에는 approvalspending_approval_count 속성이 포함됩니다.

{
  "status": "created",
  "pending_approval_count": 0,
  "approvals": [
    {
      "user": {
        "id": 49,
        "username": "project_6_bot",
        "name": "****",
        "state": "active",
        "avatar_url": "https://www.gravatar.com/avatar/e83ac685f68ea07553ad3054c738c709?s=80&d=identicon",
        "web_url": "http://localhost:3000/project_6_bot"
      },
      "status": "approved",
      "created_at": "2022-02-24T20:22:30.097Z",
      "comment": "Looks good to me"
    }
  ],
  ...
}

다중 승인 규칙이 구성된 경우 GitLab Premium 또는 Ultimate 사용자가 만든 배포에는 approval_summary 속성이 포함됩니다.

{
  "approval_summary": {
    "rules": [
      {
        "user_id": null,
        "group_id": 134,
        "access_level": null,
        "access_level_description": "qa-group",
        "required_approvals": 1,
        "deployment_approvals": []
      },
      {
        "user_id": null,
        "group_id": 135,
        "access_level": null,
        "access_level_description": "security-group",
        "required_approvals": 2,
        "deployment_approvals": [
          {
            "user": {
              "id": 100,
              "username": "security-user-1",
              "name": "security user-1",
              "state": "active",
              "avatar_url": "https://www.gravatar.com/avatar/e130fcd3a1681f41a3de69d10841afa9?s=80&d=identicon",
              "web_url": "http://localhost:3000/security-user-1"
            },
            "status": "approved",
            "created_at": "2022-04-11T03:37:03.058Z",
            "comment": null
          }
        ]
      }
    ]
  }
  ...
}

배포 생성

POST /projects/:id/deployments
속성 유형 필수 설명
id integer/string yes 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
environment string yes 배포를 생성할 환경의 이름
sha string yes 배포된 커밋의 SHA
ref string yes 배포된 브랜치 또는 태그의 이름
tag boolean yes 배포된 ref가 태그인지 여부를 나타내는 부울 값 (true일 경우)
status string yes 생성된 배포의 상태. running, success, failed, 또는 canceled 중 하나
curl --data "environment=production&sha=a91957a858320c0e17f3a0eca7cfacbff50ea29a&ref=main&tag=false&status=success" \
     --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/deployments"

응답 예시:

{
  "id": 42,
  "iid": 2,
  "ref": "main",
  "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
  "created_at": "2016-08-11T11:32:35.444Z",
  "status": "success",
  "user": {
    "name": "Administrator",
    "username": "root",
    "id": 1,
    "state": "active",
    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://localhost:3000/root"
  },
  "environment": {
    "id": 9,
    "name": "production",
    "external_url": "https://about.gitlab.com"
  },
  "deployable": null
}

GitLab Premium 또는 Ultimate 사용자에 의해 생성된 배포에는 approvalspending_approval_count 속성이 포함됩니다:

{
  "status": "created",
  "pending_approval_count": 0,
  "approvals": [],
  ...
}

배포 업데이트

PUT /projects/:id/deployments/:deployment_id
속성 유형 필수 설명
id integer/string yes 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
deployment_id integer yes 업데이트할 배포의 ID
status string yes 배포의 새로운 상태. running, success, failed, 또는 canceled 중 하나.
curl --request PUT --data "status=success" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/deployments/42"

응답 예시:

{
  "id": 42,
  "iid": 2,
  "ref": "main",
  "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
  "created_at": "2016-08-11T11:32:35.444Z",
  "status": "success",
  "user": {
    "name": "Administrator",
    "username": "root",
    "id": 1,
    "state": "active",
    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://localhost:3000/root"
  },
  "environment": {
    "id": 9,
    "name": "production",
    "external_url": "https://about.gitlab.com"
  },
  "deployable": null
}

GitLab Premium 또는 Ultimate 사용자에 의해 생성된 배포에는 approvalspending_approval_count 속성이 포함됩니다:

{
  "status": "created",
  "pending_approval_count": 0,
  "approvals": [
    {
      "user": {
        "id": 49,
        "username": "project_6_bot",
        "name": "****",
        "state": "active",
        "avatar_url": "https://www.gravatar.com/avatar/e83ac685f68ea07553ad3054c738c709?s=80&d=identicon",
        "web_url": "http://localhost:3000/project_6_bot"
      },
      "status": "approved",
      "created_at": "2022-02-24T20:22:30.097Z",
      "comment": "Looks good to me"
    }
  ],
  ...
}

특정 배포 삭제

running 상태가 아닌 특정 배포를 삭제합니다.

DELETE /projects/:id/deployments/:deployment_id
속성 타입 필수 여부 설명
id 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
deployment_id 정수 배포의 ID
curl --request "DELETE" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/deployments/1"

예시 응답:

{ "message": "204 배포가 삭제됨" }
{ "message": "403 금지됨" }
{ "message": "400 실행 중인 배포는 삭제할 수 없음" }
{ "message": "400 현재 환경에 배포된 배포는 삭제할 수 없음" }

배포와 관련된 병합 요청 목록

참고: 모든 배포가 병합 요청과 관련될 수 있는 것은 아닙니다. 자세한 정보는 환경에 새롭게 포함된 병합 요청을 추적를 참조하세요.

이 API는 특정 배포로 전송된 병합 요청 목록을 검색합니다:

GET /projects/:id/deployments/:deployment_id/merge_requests

이는 병합 요청 API와 동일한 형식으로 응답을 반환하며 동일한 매개변수를 지원합니다.

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/deployments/42/merge_requests"

차단된 배포의 승인 또는 거부

세부 정보: Tier: 프리미엄, 얼티메이트 Offering: GitLab.com, Self-managed, GitLab 전용

이 기능에 대한 자세한 정보는 배포 승인을 참조하세요.

POST /projects/:id/deployments/:deployment_id/approval
속성 타입 필수 여부 설명
id 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
deployment_id 정수 배포의 ID.
status 문자열 승인 상태 (approved 또는 rejected)
comment 문자열 아니요 승인과 함께 사용할 코멘트.
represented_as 문자열 아니요 승인 규칙이 여러 승인 규칙에 속하는 사용자인 경우 사용할 사용자/그룹/역할의 이름.
curl --data "status=approved&comment=제출 합격&represented_as=security" \
     --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/deployments/1/approval"

예시 응답:

{
  "user": {
    "id": 100,
    "username": "security-user-1",
    "name": "security user-1",
    "state": "active",
    "avatar_url": "https://www.gravatar.com/avatar/e130fcd3a1681f41a3de69d10841afa9?s=80&d=identicon",
    "web_url": "http://localhost:3000/security-user-1"
  },
  "status": "approved",
  "created_at": "2022-02-24T20:22:30.097Z",
  "comment":"제출 합격"
}