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.
Bereitstellungen
Verwende die REST-API, um Bereitstellungen und Bereitstellungsumgebungen zu erstellen und zu löschen.
Informationen zu Bereitstellungen
Bereitstellungen sind Anforderungen, mit denen einer bestimmter Verweis (Branch, SHA, Tag) bereitgestellt werden kann. GitHub sendet ein -deployment
Ereignis, auf das externe Dienste bei der Erstellung neuer Bereitstellungen lauschen und reagieren können. Mit Bereitstellungen können Entwickler*innen und Organisationen lose gekoppelte Tools auf Basis von Bereitstellungen erstellen, ohne sich über die Implementierungsdetails der Bereitstellung verschiedener Arten von Anwendungen Gedanken machen zu müssen (z. B. Web, nativ).
Mit Bereitstellungsstatus können externe Dienste Bereitstellungen mit dem Status error
, failure
, pending
, in_progress
, queued
oder success
kennzeichnen, den Systeme nutzen können, die auf -deployment_status
Ereignisse lauschen.
Bereitstellungsstatus können optional auch eine description
und eine log_url
enthalten. Dies wird dringend empfohlen, da sie Bereitstellungsstatus nützlicher machen. Die log_url
ist die vollständige URL der Bereitstellungsausgabe, und bei der description
handelt es sich um eine allgemeine Zusammenfassung der Ereignisse in der Bereitstellung.
GitHub sendet deployment
- und deployment_status
-Ereignisse, wenn neue Bereitstellungen und Bereitstellungsstatus erstellt werden. Dank dieser Ereignisse können Drittanbieterintegrationen Bereitstellungsanforderungen empfangen und darauf antworten und den Status einer Bereitstellung aktualisieren, wenn Fortschritte gemacht werden.
Nachfolgend findest du ein einfaches Sequenzdiagramm zur Funktionsweise dieser Interaktionen.
+---------+ +--------+ +-----------+ +-------------+
| Tooling | | GitHub | | 3rd Party | | Your Server |
+---------+ +--------+ +-----------+ +-------------+
| | | |
| Create Deployment | | |
|--------------------->| | |
| | | |
| Deployment Created | | |
|<---------------------| | |
| | | |
| | Deployment Event | |
| |---------------------->| |
| | | SSH+Deploys |
| | |-------------------->|
| | | |
| | Deployment Status | |
| |<----------------------| |
| | | |
| | | Deploy Completed |
| | |<--------------------|
| | | |
| | Deployment Status | |
| |<----------------------| |
| | | |
Denke daran, dass GitHub niemals auf deine Server zugreift. Deine Drittanbieterintegration ist für die Interaktion mit Bereitstellungsereignissen zuständig. Mehrere Systeme können auf Bereitstellungsereignisse lauschen, und jedes dieser Systeme muss entscheiden, ob es für das Pushen des Codes auf deine Server, das Erstellen des nativen Codes usw. verantwortlich ist.
Beachte, dass der repo_deployment
-OAuth-Bereich gezielten Zugriff auf Bereitstellungen und Bereitstellungsstatus gewährt, ohne Zugriff auf den Repositorycode zu gewähren, während die Bereiche public_repo
undrepo
ebenfalls dazu befähigen, Code zu schreiben.
Inaktive Bereitstellungen
Wenn du den Status einer Bereitstellung auf success
festlegst, werden alle vorherigen, nicht vorübergehenden und nicht produktionsbezogenen Umgebungsbereitstellungen im selben Repository mit demselben Umgebungsnamen inactive
. Um dies zu vermeiden, kannst du auto_inactive
beim Erstellen des Bereitstellungsstatus auf false
festlegen.
Du kannst angeben, dass eine vorübergehende Umgebung nicht mehr vorhanden ist, indem du ihre state
auf inactive
festlegst. Wenn du den state
auf inactive
festlegst, wird die Bereitstellung in GitHub als destroyed
angezeigt, und der Zugriff darauf wird entfernt.
List deployments
Simple filtering of deployments is available via query parameters:
Parameters for "List deployments"
Headers |
---|
Name, Type, Description |
accept stringSetting to |
Path parameters |
Name, Type, Description |
owner stringRequiredThe account owner of the repository. The name is not case sensitive. |
repo stringRequiredThe name of the repository. The name is not case sensitive. |
Query parameters |
Name, Type, Description |
sha stringThe SHA recorded at creation time. Default: |
ref stringThe name of the ref. This can be a branch, tag, or SHA. Default: |
task stringThe name of the task for the deployment (e.g., Default: |
environment string or nullThe name of the environment that was deployed to (e.g., Default: |
per_page integerThe number of results per page (max 100). Default: |
page integerPage number of the results to fetch. Default: |
HTTP response status codes for "List deployments"
Status code | Description |
---|---|
200 | OK |
Code samples for "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.
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
.
Parameters for "Create a deployment"
Headers |
---|
Name, Type, Description |
accept stringSetting to |
Path parameters |
Name, Type, Description |
owner stringRequiredThe account owner of the repository. The name is not case sensitive. |
repo stringRequiredThe name of the repository. The name is not case sensitive. |
Body parameters |
Name, Type, Description |
ref stringRequiredThe ref to deploy. This can be a branch, tag, or SHA. |
task stringSpecifies a task to execute (e.g., Default: |
auto_merge booleanAttempts to automatically merge the default branch into the requested ref, if it's behind the default branch. Default: |
required_contexts array of stringsThe 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 stringJSON payload with extra information about the deployment. |
environment stringName for the target deployment environment (e.g., Default: |
description string or nullShort description of the deployment. Default: |
transient_environment booleanSpecifies if the given environment is specific to the deployment and will no longer exist at some point in the future. Default: Default: |
production_environment booleanSpecifies if the given environment is one that end-users directly interact with. Default: |
HTTP response status codes for "Create a deployment"
Status code | 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. |
Code samples for "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
Parameters for "Get a deployment"
Headers |
---|
Name, Type, Description |
accept stringSetting to |
Path parameters |
Name, Type, Description |
owner stringRequiredThe account owner of the repository. The name is not case sensitive. |
repo stringRequiredThe name of the repository. The name is not case sensitive. |
deployment_id integerRequireddeployment_id parameter |
HTTP response status codes for "Get a deployment"
Status code | Description |
---|---|
200 | OK |
404 | Resource not found |
Code samples for "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. 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."
Parameters for "Delete a deployment"
Headers |
---|
Name, Type, Description |
accept stringSetting to |
Path parameters |
Name, Type, Description |
owner stringRequiredThe account owner of the repository. The name is not case sensitive. |
repo stringRequiredThe name of the repository. The name is not case sensitive. |
deployment_id integerRequireddeployment_id parameter |
HTTP response status codes for "Delete a deployment"
Status code | Description |
---|---|
204 | No Content |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
Code samples for "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