Last active
April 7, 2017 16:53
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm pretty sure this can be updated to use other git providers like GitLab and GitHub.