How do I trigger pre- and post-deployment web hooks?

When it comes to deployments, some environments require extra tasks to be executed before or after files are uploaded. DeployBot supports two types of deployment hooks: pre- and post-deploy web hooks and a post-deploy shell command hook.

Pre- and Post-deploy web hooks

Deployment web hooks are supported for all deployment server types. They require that you have a web server running on your remote machine that can be accessed by DeployBot whenever a web hook is triggered. When the hook is triggered, DeployBot will connect to your web server at the URL you specify and submit information about the triggered deployment in JSON format. You can setup the URL that your web hook is listening to on the server setup page.

Make sure your web server is always returning a 2XX HTTP response to DeployBot in order for it to be considered a success. If a pre-deployment hook returns anything other than a 2XX response, the deployment will not proceed and no files will be uploaded. If the post-deployment hook failed, DeployBot will mark the entire deployment as failed to alert you of the issue.

If you would like to protect your web hook with a password, you can use basic HTTP authentification by providing the username and password in the web hook URL, like this:

https://myuser:mylogin@www.mydomain.com/myhook

Web Hooks

Please note, if you have a firewall on your server you’ll need to whitelist DeployBot’s IPs in order to receive the hook.

Pre-launch shell commands

Pre-launch shell commands are available only for SFTP servers. DeployBot will execute these shell commands on your remote server after your updates are uploaded, but before new code becomes the current running code. This is ideal for compilation or building assets. Make sure that all of the specified shell commands return an exit status of 0 in order for them to be considered a success, otherwise the deployment will be marked as failed so you can see that there was a problem.

Post-launch shell commands

Post-launch shell commands are available only for SFTP servers. DeployBot will execute these shell commands on your remote server after the deployment is finished. This is the best place to restart your web server. Make sure that all of the specified shell commands return an exit status of 0 in order for them to be considered a success, otherwise the deployment will be marked as failed so you can see that there was a problem.

Sample of JSON data posted by DeployBot

;{
"author":"author username", // username of the author
"repository":"deploybot", // repository from which data was or will be deployed depending on whether it’s a pre or post hook
"author_name":"John Smith", // full name of the author
"comment":"example", // commit message
"author_email":"johnsmith@example.com", // email of the author
"server":"server example", // server to which data was deployed or will be deployed depending on whether it’s a pre or post hook
"environment":"development", //environment from which data was or will be deployed depending on whether it’s a pre or post hook
"revision":"5", // revision to which the deployment will be updated
"deployed_at":"deployed at date",  // time when deployment happened - timezone is included, will be null for pre hook
"repository_url":"git@example.beanstalkapp.com:/example.git", // source control url of the repository
"source":"beanstalkapp.com"  // identifier of the payload, in case you consume JSON from many vendors  }

PHP users please note that in order to get contents of a POST request in PHP you need to use the following code snippet:

@file_get_contents('php://input');

Still need help? Contact Us Contact Us