Skip to main content

deployments

Creates, updates, deletes, gets or lists a deployments resource.

Overview

Namedeployments
TypeResource
Idgithub.repos.deployments

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
idinteger (int64)Unique identifier of the deployment
node_idstring (example: MDEwOkRlcGxveW1lbnQx)
created_atstring (date-time) (example: 2012-07-20T01:19:13Z)
creatorobjectA GitHub user. (title: Simple User)
descriptionstring (example: Deploy request from hubot)
environmentstringName for the target deployment environment. (example: production)
original_environmentstring (example: staging)
payloadobject
performed_via_github_appobjectGitHub apps are a new way to extend GitHub. They can be installed directly on organizations and user accounts and granted access to specific repositories. They come with granular permissions and built-in webhooks. GitHub apps are first class actors within GitHub. (title: GitHub app)
production_environmentbooleanSpecifies if the given environment is one that end-users directly interact with. Default: false.
refstringThe ref to deploy. This can be a branch, tag, or sha. (example: topic-branch)
repository_urlstring (uri) (example: https://api.github.com/repos/octocat/example)
shastring (example: a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d)
statuses_urlstring (uri) (example: https://api.github.com/repos/octocat/example/deployments/1/statuses)
taskstringParameter to specify a task to execute (example: deploy)
transient_environmentbooleanSpecifies if the given environment is will no longer exist at some point in the future. Default: false.
updated_atstring (date-time) (example: 2012-07-20T01:19:13Z)
urlstring (uri) (example: https://api.github.com/repos/octocat/example/deployments/1)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_deploymentselectowner, repo, deployment_id
list_deploymentsselectowner, reposha, ref, task, environment, per_page, pageSimple filtering of deployments is available via query parameters:
create_deploymentinsertowner, repo, refDeployments offer a few configurable parameters with certain defaults.

The ref parameter can be any named branch, tag, or SHA. At GitHub 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.
delete_deploymentdeleteowner, repo, deployment_idIf 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.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
deployment_idintegerdeployment_id parameter
ownerstringThe account owner of the repository. The name is not case sensitive.
repostringThe name of the repository without the .git extension. The name is not case sensitive.
environmentstringThe name of the environment that was deployed to (e.g., staging or production).
pageintegerThe page number of the results to fetch. For more information, see "Using pagination in the REST API."
per_pageintegerThe number of results per page (max 100). For more information, see "Using pagination in the REST API."
refstringThe name of the ref. This can be a branch, tag, or SHA.
shastringThe SHA recorded at creation time.
taskstringThe name of the task for the deployment (e.g., deploy or deploy:migrations).

SELECT examples

Response

SELECT
id,
node_id,
created_at,
creator,
description,
environment,
original_environment,
payload,
performed_via_github_app,
production_environment,
ref,
repository_url,
sha,
statuses_url,
task,
transient_environment,
updated_at,
url
FROM github.repos.deployments
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND deployment_id = '{{ deployment_id }}' -- required
;

INSERT examples

Deployments offer a few configurable parameters with certain defaults.

The ref parameter can be any named branch, tag, or SHA. At GitHub 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.

INSERT INTO github.repos.deployments (
ref,
task,
auto_merge,
required_contexts,
payload,
environment,
description,
transient_environment,
production_environment,
owner,
repo
)
SELECT
'{{ ref }}' /* required */,
'{{ task }}',
{{ auto_merge }},
'{{ required_contexts }}',
'{{ payload }}',
'{{ environment }}',
'{{ description }}',
{{ transient_environment }},
{{ production_environment }},
'{{ owner }}',
'{{ repo }}'
RETURNING
id,
node_id,
created_at,
creator,
description,
environment,
original_environment,
payload,
performed_via_github_app,
production_environment,
ref,
repository_url,
sha,
statuses_url,
task,
transient_environment,
updated_at,
url
;

DELETE examples

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 FROM github.repos.deployments
WHERE owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND deployment_id = '{{ deployment_id }}' --required
;