Webhooks & automatic deployments
Deploy a server or stack whenever a branch is pushed, with GitHub, Bitbucket, GitLab or any Git host.
With automatic deployments, a server or stack deploys by itself whenever its branch is pushed, including when a pull request is merged into it. Your Git host tells Donkey about the push by calling a webhook: a private link that belongs to the server or stack.
1. Turn on automatic deployment
- A server: once it is created, edit it, open the Automatic Deployment tab and tick Enable automatic deployments.
- A stack: edit the stack and tick Enable automatic deployments. Servers in a stack follow the stack, so turn it on there, not on each server.
Copy the Automatic Deployment Link that appears. Treat it like a password: anyone who has it can start a deployment.
2. Add the webhook to your Git host
GitHub
- In the repository, open Settings → Webhooks → Add webhook.
- Payload URL: the Automatic Deployment Link. Content type:
application/json. - Which events: Just the push event. Save.
Bitbucket
- In the repository, open Repository settings → Webhooks → Add webhook.
- URL: the Automatic Deployment Link.
- Triggers: Repository push. Save.
GitLab
- In the project, open Settings → Webhooks → Add new webhook.
- URL: the Automatic Deployment Link.
- Trigger: Push events. Save.
Use push events only. A merged pull request reaches the branch as a push, so it is deployed too.
What a push deploys
- Donkey reads the branch and commit from the call. A push to another branch is ignored, so a webhook for production on branch
maindoes nothing whendevelopis pushed. - It deploys the changes between the last successful deployment and the pushed commit, then runs the build commands and SSH commands as a deployment from the dashboard would.
- The deployment shows in the project's Deployments as an automatic one, with its log.
Each server or stack has its own link. To deploy staging from develop and production from main, add both links as two webhooks of the same repository.
Other Git hosts and scripts
For a repository on another Git server, or to deploy from a CI job, call a server's link yourself with the branch and the full commit hash:
curl -X POST "<Automatic Deployment Link>" \
-d direct=1 \
-d branch=main \
-d commitRevision=$(git rev-parse HEAD)
The commit must be on that branch and already pushed. Stack links only accept calls from GitHub, Bitbucket and GitLab.
Troubleshooting
Donkey answers every call with a short JSON message. Your Git host shows it in the webhook's recent deliveries; "success": true means a deployment started.
| Message | What to do |
|---|---|
Branches not matched | The push was to another branch. Nothing to do, or check the server's branch. |
Automatic deploy option is not enabled | Tick Enable automatic deployments on the server or stack. |
Automatic deployment is disabled when server is a part of a stack | Use the stack's link instead of the server's. |
Project is not cached, Cannot get revision | Recache the repository from the project's menu, then push again or redeliver the webhook. |
Cannot parse branch, Erroneous json data received | The call isn't a push from the project's Git host. Check the events, the content type and that the project's repository host matches. |
Server not found | The link is wrong or the server was deleted. Copy it again. |
Your plan may also limit the number of automatic deployments; the message then says so.
Still need help?
Tell us what you are trying to do and we will reply by e-mail.