Skip to main content
설명서에 자주 업데이트를 게시하며 이 페이지의 번역이 계속 진행 중일 수 있습니다. 최신 정보는 영어 설명서를 참조하세요.
GitHub AE는 현재 제한된 릴리스에 있습니다.

최근에 REST API 설명서 중 일부를 이동했습니다. 원하는 항목을 찾을 수 없는 경우 새 Branches, Collaborators, Commits, Deploy Keys, Deployments, GitHub Pages, Releases, Metrics, Webhooks REST API 페이지를 사용해 볼 수 있습니다.

배포

REST API를 사용하여 배포 및 배포 환경을 만들고 삭제합니다.

배포 정보

배포는 특정 참조(분기, SHA, 태그)를 배포하기 위한 요청입니다. GitHub는 새 배포가 만들어질 때 외부 서비스가 수신 대기하고 조치를 취할 수 있는 deployment 이벤트를 발송합니다. 배포를 통해 개발자와 조직은 다양한 유형의 애플리케이션(예: 웹, 네이티브)을 제공하는 구현 세부 정보에 대해 걱정할 필요 없이 배포를 중심으로 느슨하게 결합된 도구를 빌드할 수 있습니다.

배포 상태를 통해 외부 서비스는 deployment_status 이벤트를 수신 대기하는 시스템이 사용할 수 있는 error, failure, pending, in_progress, queued 또는 success 상태로 배포를 표시할 수 있습니다.

배포 상태에는 배포 상태를 더 유용하게 하므로 매우 권장되는 선택 사항인 descriptionlog_url도 포함할 수 있습니다. log_url은 배포 출력에 대한 전체 URL이고 description은 배포에서 발생한 일에 대한 상위 수준 요약입니다.

GitHub는 새 배포 및 배포 상태가 만들어질 때 deploymentdeployment_status 이벤트를 발송합니다. 이러한 이벤트를 통해 타사 통합이 배포 요청에 대한 응답을 수신하고 진행 상황에 따라 배포 상태를 업데이트할 수 있습니다.

다음은 이러한 상호 작용이 작동하는 방식에 대한 간단한 시퀀스 다이어그램입니다.

+---------+             +--------+            +-----------+        +-------------+
| Tooling |             | GitHub |            | 3rd Party |        | Your Server |
+---------+             +--------+            +-----------+        +-------------+
     |                      |                       |                     |
     |  Create Deployment   |                       |                     |
     |--------------------->|                       |                     |
     |                      |                       |                     |
     |  Deployment Created  |                       |                     |
     |<---------------------|                       |                     |
     |                      |                       |                     |
     |                      |   Deployment Event    |                     |
     |                      |---------------------->|                     |
     |                      |                       |     SSH+Deploys     |
     |                      |                       |-------------------->|
     |                      |                       |                     |
     |                      |   Deployment Status   |                     |
     |                      |<----------------------|                     |
     |                      |                       |                     |
     |                      |                       |   Deploy Completed  |
     |                      |                       |<--------------------|
     |                      |                       |                     |
     |                      |   Deployment Status   |                     |
     |                      |<----------------------|                     |
     |                      |                       |                     |

GitHub는 실제로 서버에 액세스하지 않습니다. 배포 이벤트와 상호 작용하는 것은 타사 통합에 달려 있습니다. 여러 시스템이 배포 이벤트를 수신 대기할 수 있으며 서버에 코드를 푸시하고 네이티브 코드를 빌드하는 등의 책임이 있는지 여부에 대한 결정은 각 시스템에 달려 있습니다.

repo_deployment OAuth 범위는 리포지토리 코드에 대한 액세스 권한을 부여하지 않고 배포 및 배포 상태에 대한 대상 액세스 권한을 부여하지만 repo 범위는 코드에도 권한을 부여합니다.

비활성 배포

배포 상태를 success로 설정하면 동일한 환경 이름이 있는 동일한 리포지토리에서 이전의 모든 영구 비프로덕션 환경 배포가 inactive됩니다. 이를 방지하려면 배포 상태를 만들 때 auto_inactivefalse로 설정할 수 있습니다.

stateinactive로 설정하여 임시 환경이 더 이상 존재하지 않음을 알릴 수 있습니다. stateinactive로 설정하면 GitHub에서 배포가 destroyed로 표시되고 이에 대한 액세스가 제거됩니다.

List deployments

에서 작동 GitHub Apps

Simple filtering of deployments is available via query parameters:

"List deployments"에 대한 매개 변수

헤더
속성, 형식, Description
acceptstring

Setting to application/vnd.github+json is recommended.

경로 매개 변수
속성, 형식, Description
ownerstring필수

The account owner of the repository. The name is not case sensitive.

repostring필수

The name of the repository. The name is not case sensitive.

쿼리 매개 변수
속성, 형식, Description
shastring

The SHA recorded at creation time.

기본값: none

refstring

The name of the ref. This can be a branch, tag, or SHA.

기본값: none

taskstring

The name of the task for the deployment (e.g., deploy or deploy:migrations).

기본값: none

environmentstring or null

The name of the environment that was deployed to (e.g., staging or production).

기본값: none

per_pageinteger

The number of results per page (max 100).

기본값: 30

pageinteger

Page number of the results to fetch.

기본값: 1

"List deployments"에 대한 HTTP 응답 상태 코드

상태 코드Description
200

OK

"List deployments"에 대한 코드 샘플

get/repos/{owner}/{repo}/deployments
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/repos/OWNER/REPO/deployments

Response

Status: 200
[ { "url": "https://api.github.com/repos/octocat/example/deployments/1", "id": 1, "node_id": "MDEwOkRlcGxveW1lbnQx", "sha": "a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d", "ref": "topic-branch", "task": "deploy", "payload": {}, "original_environment": "staging", "environment": "production", "description": "Deploy request from hubot", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "created_at": "2012-07-20T01:19:13Z", "updated_at": "2012-07-20T01:19:13Z", "statuses_url": "https://api.github.com/repos/octocat/example/deployments/1/statuses", "repository_url": "https://api.github.com/repos/octocat/example", "transient_environment": false, "production_environment": true } ]

Create a deployment

에서 작동 GitHub Apps

Deployments offer a few configurable parameters with certain defaults.

The ref parameter can be any named branch, tag, or SHA. At GitHub AE we often deploy branches and verify them before we merge a pull request.

The environment parameter allows deployments to be issued to different runtime environments. Teams often have multiple environments for verifying their applications, such as production, staging, and qa. This parameter makes it easier to track which environments have requested deployments. The default environment is production.

The auto_merge parameter is used to ensure that the requested ref is not behind the repository's default branch. If the ref is behind the default branch for the repository, we will attempt to merge it for you. If the merge succeeds, the API will return a successful merge commit. If merge conflicts prevent the merge from succeeding, the API will return a failure response.

By default, commit statuses for every submitted context must be in a success state. The required_contexts parameter allows you to specify a subset of contexts that must be success, or to specify contexts that have not yet been submitted. You are not required to use commit statuses to deploy. If you do not require any contexts or create any commit statuses, the deployment will always succeed.

The payload parameter is available for any extra information that a deployment system might need. It is a JSON text field that will be passed on when a deployment event is dispatched.

The task parameter is used by the deployment system to allow different execution paths. In the web world this might be deploy:migrations to run schema changes on the system. In the compiled world this could be a flag to compile an application with debugging enabled.

Users with repo or repo_deployment scopes can create a deployment for a given ref.

Merged branch response

You will see this response when GitHub automatically merges the base branch into the topic branch instead of creating a deployment. This auto-merge happens when:

  • Auto-merge option is enabled in the repository
  • Topic branch does not include the latest changes on the base branch, which is master in the response example
  • There are no merge conflicts

If there are no new commits in the base branch, a new request to create a deployment should give a successful response.

Merge conflict response

This error happens when the auto_merge option is enabled and when the default branch (in this case master), can't be merged into the branch that's being deployed (in this case topic-branch), due to merge conflicts.

Failed commit status checks

This error happens when the required_contexts parameter indicates that one or more contexts need to have a success status for the commit to be deployed, but one or more of the required contexts do not have a state of success.

"Create a deployment"에 대한 매개 변수

헤더
속성, 형식, Description
acceptstring

Setting to application/vnd.github+json is recommended.

경로 매개 변수
속성, 형식, Description
ownerstring필수

The account owner of the repository. The name is not case sensitive.

repostring필수

The name of the repository. The name is not case sensitive.

본문 매개 변수
속성, 형식, Description
refstring필수

The ref to deploy. This can be a branch, tag, or SHA.

taskstring

Specifies a task to execute (e.g., deploy or deploy:migrations).

기본값: deploy

auto_mergeboolean

Attempts to automatically merge the default branch into the requested ref, if it's behind the default branch.

기본값: true

required_contextsarray of strings

The status contexts to verify against commit status checks. If you omit this parameter, GitHub verifies all unique contexts before creating a deployment. To bypass checking entirely, pass an empty array. Defaults to all unique contexts.

payloadobject or string

JSON payload with extra information about the deployment.

environmentstring

Name for the target deployment environment (e.g., production, staging, qa).

기본값: production

descriptionstring or null

Short description of the deployment.

기본값: ""

transient_environmentboolean

Specifies if the given environment is specific to the deployment and will no longer exist at some point in the future. Default: false

기본값: false

production_environmentboolean

Specifies if the given environment is one that end-users directly interact with. Default: true when environment is production and false otherwise.

"Create a deployment"에 대한 HTTP 응답 상태 코드

상태 코드Description
201

Created

202

Merged branch response

409

Conflict when there is a merge conflict or the commit's status checks failed

422

Validation failed, or the endpoint has been spammed.

"Create a deployment"에 대한 코드 샘플

post/repos/{owner}/{repo}/deployments
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/repos/OWNER/REPO/deployments \ -d '{"ref":"topic-branch","payload":"{ \"deploy\": \"migrate\" }","description":"Deploy request from hubot"}'

Simple example

Status: 201
{ "url": "https://api.github.com/repos/octocat/example/deployments/1", "id": 1, "node_id": "MDEwOkRlcGxveW1lbnQx", "sha": "a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d", "ref": "topic-branch", "task": "deploy", "payload": {}, "original_environment": "staging", "environment": "production", "description": "Deploy request from hubot", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "created_at": "2012-07-20T01:19:13Z", "updated_at": "2012-07-20T01:19:13Z", "statuses_url": "https://api.github.com/repos/octocat/example/deployments/1/statuses", "repository_url": "https://api.github.com/repos/octocat/example", "transient_environment": false, "production_environment": true }

Get a deployment

에서 작동 GitHub Apps

"Get a deployment"에 대한 매개 변수

헤더
속성, 형식, Description
acceptstring

Setting to application/vnd.github+json is recommended.

경로 매개 변수
속성, 형식, Description
ownerstring필수

The account owner of the repository. The name is not case sensitive.

repostring필수

The name of the repository. The name is not case sensitive.

deployment_idinteger필수

deployment_id parameter

"Get a deployment"에 대한 HTTP 응답 상태 코드

상태 코드Description
200

OK

404

Resource not found

"Get a deployment"에 대한 코드 샘플

get/repos/{owner}/{repo}/deployments/{deployment_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/repos/OWNER/REPO/deployments/DEPLOYMENT_ID

Response

Status: 200
{ "url": "https://api.github.com/repos/octocat/example/deployments/1", "id": 1, "node_id": "MDEwOkRlcGxveW1lbnQx", "sha": "a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d", "ref": "topic-branch", "task": "deploy", "payload": {}, "original_environment": "staging", "environment": "production", "description": "Deploy request from hubot", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "created_at": "2012-07-20T01:19:13Z", "updated_at": "2012-07-20T01:19:13Z", "statuses_url": "https://api.github.com/repos/octocat/example/deployments/1/statuses", "repository_url": "https://api.github.com/repos/octocat/example", "transient_environment": false, "production_environment": true }

Delete a deployment

에서 작동 GitHub Apps

If the repository only has one deployment, you can delete the deployment regardless of its status. If the repository has more than one deployment, you can only delete inactive deployments. This ensures that repositories with multiple deployments will always have an active deployment. Anyone with repo or repo_deployment scopes can delete a deployment.

To set a deployment as inactive, you must:

  • Create a new deployment that is active so that the system has a record of the current state, then delete the previously active deployment.
  • Mark the active deployment as inactive by adding any non-successful deployment status.

For more information, see "Create a deployment" and "Create a deployment status."

"Delete a deployment"에 대한 매개 변수

헤더
속성, 형식, Description
acceptstring

Setting to application/vnd.github+json is recommended.

경로 매개 변수
속성, 형식, Description
ownerstring필수

The account owner of the repository. The name is not case sensitive.

repostring필수

The name of the repository. The name is not case sensitive.

deployment_idinteger필수

deployment_id parameter

"Delete a deployment"에 대한 HTTP 응답 상태 코드

상태 코드Description
204

No Content

404

Resource not found

422

Validation failed, or the endpoint has been spammed.

"Delete a deployment"에 대한 코드 샘플

delete/repos/{owner}/{repo}/deployments/{deployment_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ https://HOSTNAME/api/v3/repos/OWNER/REPO/deployments/DEPLOYMENT_ID

Response

Status: 204