Skip to content

Instantly share code, notes, and snippets.

@zomars
Last active April 7, 2017 16:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zomars/64d512a109e69b6d90003bf38ba54239 to your computer and use it in GitHub Desktop.
Save zomars/64d512a109e69b6d90003bf38ba54239 to your computer and use it in GitHub Desktop.
Script to deploy from bitbucket via webhook and bobdenotter's Boltflow script (https://github.com/bobdenotter/boltflow)
<?php
$repo_dir = '/home/username';
$branch_to_deploy = 'master';
$update = false;
// Parse data from Bitbucket hook payload
$payload = json_decode($_POST['payload']);
if (empty($payload->commits)) {
// When merging and pushing to bitbucket, the commits array will be empty.
// In this case there is no way to know what branch was pushed to, so we will do an update.
$update = true;
} else {
foreach ($payload->commits as $commit) {
$branch = $commit->branch;
if ($branch === $branch_to_deploy || isset($commit->branches) && in_array($branch_to_deploy, $commit->branches)) {
$update = true;
break;
}
}
}
if ($update) {
// Run boltflow and save the output
$output = shell_exec('cd ' . $repo_dir . ' && ./boltflow.sh');
// Log the deployment
file_put_contents('deploy.log', date('m/d/Y h:i:s a') . " Deployed branch: " . $branch . "\n" . $output . "\n", FILE_APPEND);
}
@zomars
Copy link
Author

zomars commented Apr 6, 2017

I'm pretty sure this can be updated to use other git providers like GitLab and GitHub.

@zomars
Copy link
Author

zomars commented Apr 6, 2017

This script also assumes you have previously followed Boltflow setup process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment