Deployments API

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

GitLab CI/CD 작업 토큰의 지원은 GitLab 16.2에서 소개되었습니다.

프로젝트 배포 디렉터리

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

GET /projects/:id/deployments
속성 유형 필수 여부 설명
id 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL-encoded path.
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
      },
      "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
    },
    ...
  }
}

통합 승인 설정이 구성된 경우, 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 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
environment 문자열 배포를 위해 환경의 이름
sha 문자열 배포된 커밋의 SHA 값
ref 문자열 배포된 브랜치 또는 태그의 이름
tag 불리언 배포된 ref가 태그인 경우(true)를 나타내는 부울 값 또는 그렇지 않은 경우(false)를 나타내는 부울 값
status 문자열 생성된 배포의 상태. 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 integer/string yes 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩 경로
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 배포가 삭제됨" }
{ "message": "403 금지됨" }
{ "message": "400 실행 중인 배포를 삭제할 수 없음" }
{ "message": "400 현재 환경에 배포된 배포" }

배포와 연관된 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
History

이 기능에 대한 자세한 내용은 배포 승인을 참조하십시오.

POST /projects/:id/deployments/:deployment_id/approval
속성 유형 필수 설명
id integer/string yes 인증된 사용자 소유의 프로젝트의 ID 또는 URL 인코딩 경로.
deployment_id integer yes 배포의 ID.
status string yes 승인 상태 (approved 또는 rejected).
comment string no 승인에 대한 코멘트
represented_as string no 사용자가 다중 승인 규칙에 속하는 경우 승인에 사용할 사용자/그룹/역할의 이름.
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"
}