|
| 1 | +--- |
| 2 | +title:Deployments | GitHub API |
| 3 | +--- |
| 4 | + |
| 5 | +#Deployments |
| 6 | + |
| 7 | +* TOC |
| 8 | +{:toc} |
| 9 | + |
| 10 | +<divclass="alert"> |
| 11 | + <p> |
| 12 | +The Deployments API is currently available for developers to preview. |
| 13 | +During the preview period, the API may change without advance notice. |
| 14 | +Please see the <a href="/changes/2014-01-09-preview-the-new-deployments-api/">blog post</a> for full details. |
| 15 | + </p> |
| 16 | + |
| 17 | + <p> |
| 18 | +To access the API during the preview period, you must provide a custom <a href="/v3/media">media type</a> in the <code>Accept</code> header: |
| 19 | +<pre>application/vnd.github.cannonball-preview+json</pre> |
| 20 | + </p> |
| 21 | +</div> |
| 22 | + |
| 23 | +Deployments are a request for a specific ref(branch,sha,tag) to be deployed. |
| 24 | +GitHub then dispatches deployment events that external services can listen for |
| 25 | +and act on. This enables developers and organizations to build loosely-coupled |
| 26 | +tooling around deployments, without having to worry about implementation |
| 27 | +details of delivering different types of applications (e.g., web, native). |
| 28 | + |
| 29 | +Deployment Statuses allow external services to mark deployments with a |
| 30 | +'success', 'failure', 'error', or 'pending' state, which can then be consumed |
| 31 | +by any system listening for`deployment_status` events. |
| 32 | + |
| 33 | +Deployment Statuses can also include an optional`description` and`target_url`, and |
| 34 | +we highly recommend providing them as they make deployment statuses much more |
| 35 | +useful. The`target_url` would be the full URL to the deployment output, and |
| 36 | +the`description` would be the high level summary of what happened with the |
| 37 | +deployment. |
| 38 | + |
| 39 | +Deployments and Deployment Statuses both have associated repository events when |
| 40 | +they're created. This allows web hooks and 3rd party integrations to respond to |
| 41 | +deployment requests as well as update the status of a deployment as progress is |
| 42 | +made. |
| 43 | + |
| 44 | +Below is a simple sequence diagram for how these interactions would work. |
| 45 | + |
| 46 | +<pre> |
| 47 | ++---------+ +--------+ +-----------+ +-------------+ |
| 48 | +| Tooling | | GitHub | | 3rd Party | | Your Server | |
| 49 | ++---------+ +--------+ +-----------+ +-------------+ |
| 50 | + | | | | |
| 51 | + | Create Deployment | | | |
| 52 | + |--------------------->| | | |
| 53 | + | | | | |
| 54 | + | Deployment Created | | | |
| 55 | + |<---------------------| | | |
| 56 | + | | | | |
| 57 | + | | Deployment Event | | |
| 58 | + | |---------------------->| | |
| 59 | + | | | SSH+Deploys | |
| 60 | + | | |-------------------->| |
| 61 | + | | | | |
| 62 | + | | Deployment Status | | |
| 63 | + | |<----------------------| | |
| 64 | + | | | | |
| 65 | + | | | Deploy Completed | |
| 66 | + | | |<--------------------| |
| 67 | + | | | | |
| 68 | + | | Deployment Status | | |
| 69 | + | |<----------------------| | |
| 70 | + | | | | |
| 71 | +</pre> |
| 72 | + |
| 73 | +Keep in mind that GitHub is never actually accessing your servers. It's up to |
| 74 | +your 3rd party integration to interact with deployment events. |
| 75 | +This allows for[github-services](https://github.com/github/github-services) |
| 76 | +integrations as well as running your own systems depending on your use case. |
| 77 | +Multiple systems can listen for deployment events, and it's up to each of |
| 78 | +those systems to decide whether or not they're responsible for pushing the code |
| 79 | +out to your servers, building native code, etc. |
| 80 | + |
| 81 | +Note that the`repo:deployment`[OAuth scope](/v3/oauth/#scopes) grants |
| 82 | +targeted access to Deployments and Deployment Statuses**without** |
| 83 | +granting access to repository code, while the`repo` scope grants permission to code |
| 84 | +as well. |
| 85 | + |
| 86 | +##List Deployments |
| 87 | + |
| 88 | +Users with pull access can view deployments for a repository: |
| 89 | + |
| 90 | +GET /repos/:owner/:repo/deployments |
| 91 | + |
| 92 | +###Response |
| 93 | + |
| 94 | +<%= headers 200,:pagination => default_pagination_rels %> |
| 95 | +<%= json(:deployment) { |h|[h] } %> |
| 96 | + |
| 97 | +##Create a Deployment |
| 98 | + |
| 99 | +If your repository is taking advantage of[commit statuses](/v3/repos/statuses), |
| 100 | +the API will reject requests that do not have a success status. (Your repository |
| 101 | +is not required to use commit statuses. If no commit statuses are present, the |
| 102 | +deployment will always be created.) |
| 103 | + |
| 104 | +The`force` parameter can be used when you really just need a deployment to go |
| 105 | +out. In these cases, all checks are bypassed, and the deployment is created for |
| 106 | +the ref. |
| 107 | + |
| 108 | +The`auto_merge` parameter is used to ensure that the requested ref is not |
| 109 | +behind the repository's default branch. If the ref*is* behind the default |
| 110 | +branch for the repository, we will attempt to merge it for you. If the merge |
| 111 | +succeeds, the API will return a successful merge commit. If merge conflicts |
| 112 | +prevent the merge from succeeding, the API will return a failure response. |
| 113 | + |
| 114 | +The`payload` parameter is available for any extra information that a |
| 115 | +deployment system might need. It is a JSON text field that will be passed on |
| 116 | +when a deployment event is dispatched. |
| 117 | + |
| 118 | +Users with push access can create a deployment for a given ref: |
| 119 | + |
| 120 | +POST /repos/:owner/:repo/deployments |
| 121 | + |
| 122 | +###Parameters |
| 123 | + |
| 124 | +Name | Type | Description |
| 125 | +-----|------|-------------- |
| 126 | +`ref`|`string`|**Required**. The ref to deploy. This can be a branch, tag, or sha. |
| 127 | +`force`|`boolean`| Optional parameter to bypass any ahead/behind checks or commit status checks. Default:`false` |
| 128 | +`payload`|`string` | Optional JSON payload with extra information about the deployment. Default:`""` |
| 129 | +`auto_merge`|`boolean`| Optional parameter to merge the default branch into the requested deployment branch if necessary. Default:`false` |
| 130 | +`description`|`string` | Optional short description. Default:`""` |
| 131 | + |
| 132 | +####Example |
| 133 | + |
| 134 | +<%= json\ |
| 135 | +:ref => "topic-branch", |
| 136 | +:payload => "{\"environment\":\"production\",\"deploy_user\":\"atmos\",\"room_id\":123456}", |
| 137 | +:description => "Deploying my sweet branch" |
| 138 | +%> |
| 139 | + |
| 140 | +<%= headers 201, |
| 141 | +:Location => |
| 142 | +'https://api.github.com/repos/octocat/example/deployments/1' %> |
| 143 | +<%= json:deployment %> |
| 144 | + |
| 145 | +##Update a Deployment |
| 146 | + |
| 147 | +Once a deployment is created, it cannot be updated. Information relating to the |
| 148 | +success or failure of a deployment is handled through Deployment Statuses. |
| 149 | + |
| 150 | +#Deployment Statuses |
| 151 | + |
| 152 | +##List Deployment Statuses |
| 153 | + |
| 154 | +Users with pull access can view deployment statuses for a deployment: |
| 155 | + |
| 156 | +GET /repos/:owner/:repo/deployments/:id/statuses |
| 157 | + |
| 158 | +###Parameters |
| 159 | + |
| 160 | +Name | Type | Description |
| 161 | +-----|------|-------------- |
| 162 | +`id` |`integer`|**Required**. The Deployment ID to list the statuses from. |
| 163 | + |
| 164 | + |
| 165 | +###Response |
| 166 | + |
| 167 | +<%= headers 200,:pagination => default_pagination_rels %> |
| 168 | +<%= json(:deployment_status) { |h|[h] } %> |
| 169 | + |
| 170 | +##Create a Deployment Status |
| 171 | + |
| 172 | +Users with push access can create deployment statuses for a given deployment: |
| 173 | + |
| 174 | +POST /repos/:owner/:repo/deployments/:id/statuses |
| 175 | + |
| 176 | +###Parameters |
| 177 | + |
| 178 | +Name | Type | Description |
| 179 | +-----|------|-------------- |
| 180 | +`state`|`string` |**Required**. The state of the status. Can be one of`pending`,`success`,`error`, or`failure`. |
| 181 | +`target_url`|`string` | The target URL to associate with this status. This URL should contain output to keep the user updated while the task is running or serve as historical information for what happened in the deployment. Default:`""` |
| 182 | +`description`|`string` | A short description of the status. Default:`""` |
| 183 | + |
| 184 | +####Example |
| 185 | + |
| 186 | +<%= json\ |
| 187 | +:state => "success", |
| 188 | +:target_url => "https://example.com/deployment/42/output", |
| 189 | +:description => "Deployment finished successfully." |
| 190 | +%> |
| 191 | + |
| 192 | +###Response |
| 193 | + |
| 194 | +<%= headers 201, |
| 195 | +:Location => |
| 196 | +'https://api.github.com/repos/octocat/example/deployments/42/statuses/1' %> |
| 197 | +<%= json:deployment_status %> |