Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
GitHub Docs
The REST API is now versioned.For more information, see "About API versioning."

REST API endpoints for deployments

Use the REST API to create and delete deployments and deployment environments.

About deployments

Deployments are requests to deploy a specific ref (branch, SHA, tag). GitHub dispatches adeployment event that external services can listen for and act on when new deployments are created. Deployments enable developers and organizations to build loosely coupled tooling around deployments, without having to worry about the implementation details of delivering different types of applications (e.g., web, native).

Deployment statuses allow external services to mark deployments with anerror,failure,pending,in_progress,queued, orsuccess state that systems listening todeployment_status events can consume.

Deployment statuses can also include an optionaldescription andlog_url, which are highly recommended because they make deployment statuses more useful. Thelog_url is the full URL to the deployment output, andthedescription is a high-level summary of what happened with the deployment.

GitHub dispatchesdeployment anddeployment_status events when new deployments and deployment statuses are created. These events allow third-party integrations to receive and respond to deployment requests, and update the status of a deployment as progress is made.

Below is a simple sequence diagram for how these interactions would work.

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

Keep in mind that GitHub is never actually accessing your servers. It's up to your third-party integration to interact with deployment events. Multiple systems can listen for deployment events, and it's up to each of those systems to decide whether they're responsible for pushing the code out to your servers, building native code, etc.

Note that therepo_deploymentOAuth scope grants targeted access to deployments and deployment statuseswithout granting access to repository code, while thepublic_repo andrepo scopes grant permission to code as well.

Inactive deployments

When you set the state of a deployment tosuccess, then all prior non-transient, non-production environment deployments in the same repository with the same environment name will becomeinactive. To avoid this, you can setauto_inactive tofalse when creating the deployment status.

You can communicate that a transient environment no longer exists by setting itsstate toinactive. Setting thestate toinactive shows the deployment asdestroyed in GitHub and removes access to it.

List deployments

Simple filtering of deployments is available via query parameters:

Fine-grained access tokens for "List deployments"

This endpoint works with the following fine-grained token types:

The fine-grained token must have the following permission set:

  • "Deployments" repository permissions (read)

This endpoint can be used without authentication or the aforementioned permissions if only public resources are requested.

Parameters for "List deployments"

Headers
Name, Type, Description
acceptstring

Setting toapplication/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 without the.git extension. 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 ordeploy:migrations).

Default:none

environmentstring or null

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

Default:none

per_pageinteger

The number of results per page (max 100). For more information, see "Using pagination in the REST API."

Default:30

pageinteger

The page number of the results to fetch. For more information, see "Using pagination in the REST API."

Default:1

HTTP response status codes for "List deployments"

Status codeDescription
200

OK

Code samples for "List deployments"

Request example

get/repos/{owner}/{repo}/deployments
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/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

Deployments offer a few configurable parameters with certain defaults.

Theref parameter can be any named branch, tag, or SHA. At GitHub we often deploy branches and verify thembefore we merge a pull request.

Theenvironment parameter allows deployments to be issued to different runtime environments. Teams often havemultiple environments for verifying their applications, such asproduction,staging, andqa. This parametermakes it easier to track which environments have requested deployments. The default environment isproduction.

Theauto_merge parameter is used to ensure that the requested ref is not behind the repository's default branch. Ifthe refis 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 willreturn a failure response.

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

Thepayload parameter is available for any extra information that a deployment system might need. It is a JSON textfield that will be passed on when a deployment event is dispatched.

Thetask parameter is used by the deployment system to allow different execution paths. In the web world this mightbedeploy:migrations to run schema changes on the system. In the compiled world this could be a flag to compile anapplication with debugging enabled.

Merged branch response:

You will see this response when GitHub automatically merges the base branch into the topic branch instead of creatinga 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 ismaster 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 successfulresponse.

Merge conflict response:

This error happens when theauto_merge option is enabled and when the default branch (in this casemaster), can'tbe merged into the branch that's being deployed (in this casetopic-branch), due to merge conflicts.

Failed commit status checks:

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

OAuth app tokens and personal access tokens (classic) need therepo orrepo_deployment scope to use this endpoint.

Fine-grained access tokens for "Create a deployment"

This endpoint works with the following fine-grained token types:

The fine-grained token must have the following permission set:

  • "Deployments" repository permissions (write)

Parameters for "Create a deployment"

Headers
Name, Type, Description
acceptstring

Setting toapplication/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 without the.git extension. 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 ordeploy: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

Thestatus 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

Default:false

production_environmentboolean

Specifies if the given environment is one that end-users directly interact with. Default:true whenenvironment isproduction andfalse otherwise.

HTTP response status codes for "Create a deployment"

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

Code samples for "Create a deployment"

Request example

post/repos/{owner}/{repo}/deployments
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/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

Fine-grained access tokens for "Get a deployment"

This endpoint works with the following fine-grained token types:

The fine-grained token must have the following permission set:

  • "Deployments" repository permissions (read)

This endpoint can be used without authentication or the aforementioned permissions if only public resources are requested.

Parameters for "Get a deployment"

Headers
Name, Type, Description
acceptstring

Setting toapplication/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 without the.git extension. The name is not case sensitive.

deployment_idintegerRequired

deployment_id parameter

HTTP response status codes for "Get a deployment"

Status codeDescription
200

OK

404

Resource not found

Code samples for "Get a deployment"

Request example

get/repos/{owner}/{repo}/deployments/{deployment_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/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

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 therepo orrepo_deployment scope to use this endpoint.

Fine-grained access tokens for "Delete a deployment"

This endpoint works with the following fine-grained token types:

The fine-grained token must have the following permission set:

  • "Deployments" repository permissions (write)

Parameters for "Delete a deployment"

Headers
Name, Type, Description
acceptstring

Setting toapplication/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 without the.git extension. The name is not case sensitive.

deployment_idintegerRequired

deployment_id parameter

HTTP response status codes for "Delete a deployment"

Status codeDescription
204

No Content

404

Resource not found

422

Validation failed, or the endpoint has been spammed.

Code samples for "Delete a deployment"

Request example

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

Response

Status: 204

[8]ページ先頭

©2009-2025 Movatter.jp