배포 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여야 합니다.

Example response:

[
  {
    "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 정수/문자열 프로젝트의 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에서 사용자가 생성한 배포에는 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 프로젝트의 ID 또는 URL 인코딩된 경로입니다.
environment string 배포를 생성할 환경의 이름입니다.
sha string 배포된 커밋의 SHA입니다.
ref string 배포된 브랜치 또는 태그의 이름입니다.
tag boolean 배포된 ref가 태그(true)인지 아닌지(false)를 나타내는 부울입니다.
status string 생성된 배포의 상태입니다. 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": "관리자",
    "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 프로젝트의 ID 또는 URL 인코딩된 경로입니다.
deployment_id integer 업데이트할 배포의 ID입니다.
status string 배포의 새로운 상태입니다. 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": "관리자",
    "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": "좋습니다"
    }
  ],
  ...
}

특정 배포 삭제

현재 환경에 대한 마지막 배포가 아니거나 running 상태가 아닌 특정 배포를 삭제합니다.

DELETE /projects/:id/deployments/:deployment_id
속성 유형 필수 설명
id integer/string 프로젝트의 ID 또는 URL 인코딩된 경로
deployment_id integer 배포의 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" }

배포와 연결된 병합 요청 목록

참고: 모든 배포가 병합 요청과 연결될 수 있는 것은 아닙니다. 자세한 내용은 어떤 병합 요청이 환경에 배포되었는지 추적하기를 참조하세요.

이 API는 주어진 배포와 함께 제공된 병합 요청의 목록을 검색합니다:

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

Merge requests 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

이 기능에 대한 자세한 내용은 Deployment Approvals를 참조하세요.

POST /projects/:id/deployments/:deployment_id/approval
속성 유형 필수 설명
id integer/string 프로젝트의 ID 또는 URL 인코딩된 경로.
deployment_id integer 배포의 ID.
status string 승인 상태 (approved 또는 rejected).
comment string 아니오 승인과 함께 제공할 댓글
represented_as string 아니오 승인에 사용할 사용자/그룹/역할의 이름, 사용자가 다수의 승인 규칙에 속할 때 사용.
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"
}