이 버전의 GitHub Enterprise는 다음 날짜에 중단되었습니다. 2024-03-26. 중요한 보안 문제에 대해서도 패치 릴리스가 이루어지지 않습니다. 더 뛰어난 성능, 향상된 보안, 새로운 기능을 위해 최신 버전의 GitHub Enterprise Server로 업그레이드합니다. 업그레이드에 대한 도움말은 GitHub Enterprise 지원에 문의하세요.
배포에 대한 REST API 엔드포인트
REST API를 사용하여 배포 및 배포 환경을 만들고 삭제합니다.
배포 정보
배포는 특정 참조(분기, SHA, 태그)를 배포하기 위한 요청입니다. GitHub는 새 배포가 만들어질 때 외부 서비스가 수신 대기하고 조치를 취할 수 있는 deployment
이벤트를 발송합니다. 배포를 통해 개발자와 조직은 다양한 유형의 애플리케이션(예: 웹, 네이티브)을 제공하는 구현 세부 정보에 대해 걱정할 필요 없이 배포를 중심으로 느슨하게 결합된 도구를 빌드할 수 있습니다.
배포 상태를 통해 외부 서비스는 deployment_status
이벤트를 수신 대기하는 시스템이 사용할 수 있는 error
, failure
, pending
, in_progress
, queued
또는 success
상태로 배포를 표시할 수 있습니다.
배포 상태에는 배포 상태를 더 유용하게 하므로 매우 권장되는 선택 사항인 description
및 log_url
도 포함할 수 있습니다. log_url
은 배포 출력에 대한 전체 URL이고 description
은 배포에서 발생한 일에 대한 상위 수준 요약입니다.
GitHub는 새 배포 및 배포 상태가 만들어질 때 deployment
및 deployment_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 범위는 리포지토리 코드에 대한 액세스 권한을 부여하지 않고 배포 및 배포 상태에 대한 대상 액세스 권한을 부여하지만 public_repo
및 repo
범위는 코드에도 권한을 부여합니다.
비활성 배포
배포 상태를 success
로 설정하면 동일한 환경 이름이 있는 동일한 리포지토리에서 이전의 모든 영구 비프로덕션 환경 배포가 inactive
됩니다. 이를 방지하려면 배포 상태를 만들 때 auto_inactive
를 false
로 설정할 수 있습니다.
state
를 inactive
로 설정하여 임시 환경이 더 이상 존재하지 않음을 알릴 수 있습니다. state
를 inactive
로 설정하면 GitHub에서 배포가 destroyed
로 표시되고 이에 대한 액세스가 제거됩니다.
List deployments
Simple filtering of deployments is available via query parameters:
"List deployments"에 대한 매개 변수
이름, Type, 설명 |
---|
accept string Setting to |
이름, Type, 설명 |
---|
owner string RequiredThe account owner of the repository. The name is not case sensitive. |
repo string RequiredThe name of the repository without the |
이름, Type, 설명 |
---|
sha string The SHA recorded at creation time. 기본값: |
ref string The name of the ref. This can be a branch, tag, or SHA. 기본값: |
task string The name of the task for the deployment (e.g., 기본값: |
environment string or null The name of the environment that was deployed to (e.g., 기본값: |
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." 기본값: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." 기본값: |
"List deployments"에 대한 HTTP 응답 상태 코드
상태 코드 | 설명 |
---|---|
200 | OK |
"List deployments"에 대한 코드 샘플
요청 예제
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/deployments
Response
Status: 200
[
{
"url": "https://HOSTNAME/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://HOSTNAME/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://HOSTNAME/users/octocat/followers",
"following_url": "https://HOSTNAME/users/octocat/following{/other_user}",
"gists_url": "https://HOSTNAME/users/octocat/gists{/gist_id}",
"starred_url": "https://HOSTNAME/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://HOSTNAME/users/octocat/subscriptions",
"organizations_url": "https://HOSTNAME/users/octocat/orgs",
"repos_url": "https://HOSTNAME/users/octocat/repos",
"events_url": "https://HOSTNAME/users/octocat/events{/privacy}",
"received_events_url": "https://HOSTNAME/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://HOSTNAME/repos/octocat/example/deployments/1/statuses",
"repository_url": "https://HOSTNAME/repos/octocat/example",
"transient_environment": false,
"production_environment": true
}
]
Create a deployment
Deployments offer a few configurable parameters with certain defaults.
The ref
parameter can be any named branch, tag, or SHA. At GitHub Enterprise Server 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.
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
.
OAuth app tokens and personal access tokens (classic) need the repo
or repo_deployment
scope to use this endpoint.
"Create a deployment"에 대한 매개 변수
이름, Type, 설명 |
---|
accept string Setting to |
이름, Type, 설명 |
---|
owner string RequiredThe account owner of the repository. The name is not case sensitive. |
repo string RequiredThe name of the repository without the |
이름, Type, 설명 |
---|
ref string RequiredThe ref to deploy. This can be a branch, tag, or SHA. |
task string Specifies a task to execute (e.g., 기본값: |
auto_merge boolean Attempts to automatically merge the default branch into the requested ref, if it's behind the default branch. 기본값: |
required_contexts array 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. |
payload object or string JSON payload with extra information about the deployment. |
environment string Name for the target deployment environment (e.g., 기본값: |
description string or null Short description of the deployment. 기본값: |
transient_environment boolean Specifies if the given environment is specific to the deployment and will no longer exist at some point in the future. Default: 기본값: |
production_environment boolean Specifies if the given environment is one that end-users directly interact with. Default: |
"Create a deployment"에 대한 HTTP 응답 상태 코드
상태 코드 | 설명 |
---|---|
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"에 대한 코드 샘플
요청 예제
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://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://HOSTNAME/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://HOSTNAME/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://HOSTNAME/users/octocat/followers",
"following_url": "https://HOSTNAME/users/octocat/following{/other_user}",
"gists_url": "https://HOSTNAME/users/octocat/gists{/gist_id}",
"starred_url": "https://HOSTNAME/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://HOSTNAME/users/octocat/subscriptions",
"organizations_url": "https://HOSTNAME/users/octocat/orgs",
"repos_url": "https://HOSTNAME/users/octocat/repos",
"events_url": "https://HOSTNAME/users/octocat/events{/privacy}",
"received_events_url": "https://HOSTNAME/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://HOSTNAME/repos/octocat/example/deployments/1/statuses",
"repository_url": "https://HOSTNAME/repos/octocat/example",
"transient_environment": false,
"production_environment": true
}
Get a deployment
"Get a deployment"에 대한 매개 변수
이름, Type, 설명 |
---|
accept string Setting to |
이름, Type, 설명 |
---|
owner string RequiredThe account owner of the repository. The name is not case sensitive. |
repo string RequiredThe name of the repository without the |
deployment_id integer Requireddeployment_id parameter |
"Get a deployment"에 대한 HTTP 응답 상태 코드
상태 코드 | 설명 |
---|---|
200 | OK |
404 | Resource not found |
"Get a deployment"에 대한 코드 샘플
요청 예제
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/deployments/DEPLOYMENT_ID
Response
Status: 200
{
"url": "https://HOSTNAME/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://HOSTNAME/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://HOSTNAME/users/octocat/followers",
"following_url": "https://HOSTNAME/users/octocat/following{/other_user}",
"gists_url": "https://HOSTNAME/users/octocat/gists{/gist_id}",
"starred_url": "https://HOSTNAME/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://HOSTNAME/users/octocat/subscriptions",
"organizations_url": "https://HOSTNAME/users/octocat/orgs",
"repos_url": "https://HOSTNAME/users/octocat/repos",
"events_url": "https://HOSTNAME/users/octocat/events{/privacy}",
"received_events_url": "https://HOSTNAME/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://HOSTNAME/repos/octocat/example/deployments/1/statuses",
"repository_url": "https://HOSTNAME/repos/octocat/example",
"transient_environment": false,
"production_environment": true
}
Delete a deployment
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.
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."
OAuth app tokens and personal access tokens (classic) need the repo
or repo_deployment
scope to use this endpoint.
"Delete a deployment"에 대한 매개 변수
이름, Type, 설명 |
---|
accept string Setting to |
이름, Type, 설명 |
---|
owner string RequiredThe account owner of the repository. The name is not case sensitive. |
repo string RequiredThe name of the repository without the |
deployment_id integer Requireddeployment_id parameter |
"Delete a deployment"에 대한 HTTP 응답 상태 코드
상태 코드 | 설명 |
---|---|
204 | No Content |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
"Delete a deployment"에 대한 코드 샘플
요청 예제
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/deployments/DEPLOYMENT_ID
Response
Status: 204