배포 API

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

GitLab 16.2에서 GitLab CI/CD 작업 토큰 인증 지원이 추가되었습니다.

프로젝트 배포 디렉터리

프로젝트 내 배포 디렉터리을 가져옵니다.

GET /projects/:id/deployments
속성 유형 필수여부 설명
id 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
order_by 문자열 아니오 id, iid, created_at, updated_at, finished_at, 또는 ref 중 하나로 배포를 정렬합니다. 기본값은 id입니다.
sort 문자열 아니오 asc 또는 desc 순서로 정렬된 배포를 반환합니다. 기본값은 asc입니다.
updated_after 날짜/시간 아니오 지정된 날짜 이후에 업데이트된 배포를 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 예상됩니다.
updated_before 날짜/시간 아니오 지정된 날짜 전에 업데이트된 배포를 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 예상됩니다.
finished_after 날짜/시간 아니오 지정된 날짜 이후에 완료된 배포를 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 예상됩니다.
finished_before 날짜/시간 아니오 지정된 날짜 전에 완료된 배포를 반환합니다. ISO 8601 형식(2019-03-15T08:00:00Z)으로 예상됩니다.
environment 문자열 아니오 배포를 환경의 이름으로 필터링합니다.
status 문자열 아니오 created, running, success, failed, canceled, 또는 blocked 중 하나로 배포를 필터링합니다.
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/deployments"
note
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
      },
      ...
    },
    "environment": {
      "external_url": "https://about.gitlab.com",
      "id": 9,
      "name": "production"
    },
    "id": 41,
    "iid": 1,
    "ref": "main",
    ...
  },
  {
    ...
  }
]
특정 배포 가져오기

GET /projects/:id/deployments/:deployment_id
속성 유형 필수 설명
id 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL-인코딩된 경로
deployment_id 정수 배포의 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-encoded path
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-encoded path
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 integer/string yes 인증된 사용자가 소유한 프로젝트의 ID 또는 URL-encoded path
deployment_id integer yes 삭제할 배포의 ID
curl --request "DELETE" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/deployments/1"

예시 응답:

{ "message": "204 Deployment destroyed" }
{ "message": "403 Forbidden" }
{ "message": "400 Cannot destroy running deployment" }
{ "message": "400 Deployment currently deployed to environment" }

배포와 관련된 Merge Request 디렉터리

note
모든 배포가 Merge Request과 관련될 수 있는 것은 아닙니다. 자세한 정보는 특정 배포에 포함된 새로운 Merge Request을 추적를 참조하세요.

이 API는 주어진 배포와 함께 제공된 Merge Request 디렉터리을 검색합니다:

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

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

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

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

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

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

POST /projects/:id/deployments/:deployment_id/approval
속성 유형 필수 설명
id 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
deployment_id 정수 배포의 ID
status 문자열 승인 상태 (approved 또는 rejected)
comment 문자열 아니오 승인과 함께 추가할 코멘트
represented_as 문자열 아니오 사용자가 다중 승인 규칙에 속할 때 승인에 사용할 사용자/그룹/역할의 이름
curl --data "status=approved&comment=Looks good to me&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":"Looks good to me"
}