Chapter 5

Automatic deployments

Automatically deploy code from your repository

DeployHQ supports automatic deployments from a number of repository hosting services, meaning you can run a deployment when code is pushed to your repository without logging into DeployHQ to start it. The currently supported repository hosts are:

Each server or group in your project has a unique automatic deployment URL, this is a URL that you can add to your repository as a webhook, so DeployHQ is notified when new commits are pushed to your repository.

Getting the webhook URL for a server

Firstly navigate to the "Servers and Groups" page via the Settings on a given Project page, then click the name of your server, or the edit icon next to your server in the list to edit it:

Servers list

Head to the bottom of the page, ensuring that Enable auto deployments? is enabled, then copy the URL just below to your clipboard.

Automatic deployment settings

Adding the webhook to your Bitbucket repository

Open your repository up in BitBucket (there's a shortcut at the top of DeployHQ labelled "Browse Repository") and click Settings, followed by Webhooks in the adjacent menu. Then, click Add webhook:

Bitbucket webhooks

Enter a meaningful name for your Webhook, then paste the URL from your server in DeployHQ into the box into the URL field. Ensure that Status is set to Active, keep Repository Push selected next to Triggers and hit Save to finish.

New webhook in Bitbucket

Adding the webhook to your Codebase repository

Open your repository up in Codebase (there's a shortcut at the top of DeployHQ labelled Browse Repository) and click the Settings button on the right hand side.

Repository Settings in Codebase

Paste the webook URL from your server in DeployHQ into the Post-Receive Hooks URL field at the bottom of your hooks list, leaving it set to Post Request, then click Add to finish.

Codebase webhook

Adding the webhook to your Github repository

Open your repository up in GitHub (there's a shortcut at the top of DeployHQ labelled "Browse Repository") and click the Settings tab at the top of the screen. Next click Webhooks on the left hand side, then Add webhook at the top:

Github webhook

Enter the URL from DeployHQ into the Payload URL, select application/x-www-form-urlencoded as the Content type and hit Add webhook.

Adding the webhook to your Gitlab repository

Open your repository up in Gitlab (there's a shortcut at the top of DeployHQ labelled "Browse Repository") and navigate to the Settings tab on the left hand side of the page, followed by the Integrations sub-menu below:

Gitlab webhook

Paste your webhook URL into the URL field, ensure only Push events are enabled checked within the Trigger options, then click Add webhook to finish.

Please note, if you're adding the webhook to a self hosted Gitlab repository, you'll need to make sure you select the repository host as Gitlab in your repository configuration first.

Adding the webhook to your Planio repository

Open your repository settings up in Planio by clicking the Settings tab within your project, then the Edit button next to the repository in the list:

Planio repository webhook

Paste the webhook URL from Deploy into the Post-Receive webhook URL field and click Save to finish.

Post-receive hook URL

Specifying a branch to deploy from

The automatic deployment process will check the branch configured for your server (the Branch to deploy from) each time a request is posted to the webhook URL. If the branch is found to match, the deployment will be queued, otherwise it will be ignored. If you wish to change the branch, just navigate to your server settings in DeployHQ, then update the Branch to Deploy from found under Deployment Options.

Automatically deploying using your own custom trigger

As well as through the supported repository hosts, you can set up your own auto deployment trigger via a JSON POST request, which many other services have integrations for. To set this up, simply navigate to a server's setting's within your project:

Then locate the POST URL:

If you navigate to the URL in a browser, it will display the necessary JSON payload required to send a request to the url to trigger a deployment.

The payload to use is:

    "new_ref": "aabbccddeeff",  
    "branch": "master",
    "email": "user@example.com",
    "clone_url": "git@yourhost:path"
  • new_ref is the revision you wish to deploy to.
  • branch is the branch the revision is on (not used in SVN).
  • email is the email address to be notified on completion.
  • clone_url is the path to your repository (as entered in the Deploy UI).