Skip to main content

このバージョンの GitHub Enterprise はこの日付をもって終了となりました: 2022-10-12. 重大なセキュリティの問題に対してであっても、パッチリリースは作成されません。 パフォーマンスの向上、セキュリティの向上、新機能の向上を図るために、最新バージョンの GitHub Enterprise にアップグレードします。 アップグレードに関するヘルプについては、GitHub Enterprise サポートにお問い合わせく� さい

We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the new Branches, Collaborators, Commits, Deploy Keys, Deployments, GitHub Pages, Releases, Metrics, Webhooks REST API pages.

デプロイメント

Deployments API を使うと、デプロイとデプロイ環境を作成および削除できます。

デプロイ API について

デプロイメントとは、特定の ref (ブランチ、SHA、タグ) を配備するためるリクエストです。 GitHub では、deployment イベントがディスパッチされますが、このイベントでは、新しいデプロイが作成されるタイミングを外部サービスがリッスンし、それに応じて動作できます。 デプロイメントにより、開発者や Organization はデプロイメントを中心として、さまざまな種類のアプリケーション (ウェブ、ネイティブなど) を提供するための実装に関する詳細を気にすることなく、疎結合ツールを構築できます。

デプロイ状態という機能では、外部サービスはデプロイに、deployment_status イベントをリッスンするシステ� が利用できる errorfailurependingin_progressqueuedsuccess という状態を付けることができます。

デプロイ状態には、任意で descriptionlog_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_inactivefalse に設定できます。

その stateinactive に設定することで、一時的な環境がなくなったことを通知できます。 stateinactive に設定すると、GitHub でデプロイが destroyed として表示され、それへのアクセスが削除されます。

List deployments

次のもので機能します GitHub Apps

Simple filtering of deployments is available via query parameters:

パラメーター

Headers
Name, Type, Description
acceptstring

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

See preview notice
Path parameters
Name, Type, Description
ownerstringRequired

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

repostringRequired

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

Query parameters
Name, Type, Description
shastring

The SHA recorded at creation time.

Default: none

refstring

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

Default: none

taskstring

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

Default: none

environmentstringnull

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

Default: none

per_pageinteger

The number of results per page (max 100).

Default: 30

pageinteger

Page number of the results to fetch.

Default: 1

HTTP 応答状態コード

status code説明
200

OK

コード サンプル

get/repos/{owner}/{repo}/deployments
curl \ -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://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 } ]

プレビュー通知

The inactive state and the log_url, environment_url, and auto_inactive parameters are currently available for developers to preview. Please see the blog post for full details.

To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.ant-man-preview+json

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 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.

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.

パラメーター

Headers
Name, Type, Description
acceptstring

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

See preview notice
Path parameters
Name, Type, Description
ownerstringRequired

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

repostringRequired

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

Body parameters
Name, Type, Description
refstringRequired

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

taskstring

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

Default: deploy

auto_mergeboolean

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

Default: 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).

Default: production

descriptionstring or null

Short description of the deployment.

Default: ""

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
Note: This parameter requires you to use the application/vnd.github.ant-man-preview+json custom media type.

Default: 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.
Note: This parameter requires you to use the application/vnd.github.ant-man-preview+json custom media type.

HTTP 応答状態コード

status code説明
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.

コード サンプル

post/repos/{owner}/{repo}/deployments
curl \ -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://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 }

プレビュー通知

The inactive state and the log_url, environment_url, and auto_inactive parameters are currently available for developers to preview. Please see the blog post for full details.

To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.ant-man-preview+json

Get a deployment

次のもので機能します GitHub Apps

パラメーター

Headers
Name, Type, Description
acceptstring

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

See preview notices
Path parameters
Name, Type, Description
ownerstringRequired

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

repostringRequired

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

deployment_idintegerRequired

deployment_id parameter

HTTP 応答状態コード

status code説明
200

OK

404

Resource not found

コード サンプル

get/repos/{owner}/{repo}/deployments/{deployment_id}
curl \ -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://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 }

プレビュー通知

New features in the Deployments API on GitHub are currently available during a public beta. Please see the blog post for full details.

To access the new environment parameter, the two new values for the state parameter (in_progress and queued), and use auto_inactive on production deployments during the public beta period, you must provide the following custom media type in the Accept header:

application/vnd.github.flash-preview+json

The inactive state and the log_url, environment_url, and auto_inactive parameters are currently available for developers to preview. Please see the blog post for full details.

To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.ant-man-preview+json

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."

パラメーター

Headers
Name, Type, Description
acceptstring

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

Path parameters
Name, Type, Description
ownerstringRequired

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

repostringRequired

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

deployment_idintegerRequired

deployment_id parameter

HTTP 応答状態コード

status code説明
204

No Content

404

Resource not found

422

Validation failed, or the endpoint has been spammed.

コード サンプル

delete/repos/{owner}/{repo}/deployments/{deployment_id}
curl \ -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