Skip to content

Instantly share code, notes, and snippets.

@greatdg
Created May 30, 2014 07:05
Show Gist options
  • Save greatdg/4d126c51dbe7413f6808 to your computer and use it in GitHub Desktop.
Save greatdg/4d126c51dbe7413f6808 to your computer and use it in GitHub Desktop.
automated deployment from bitbucket using post hook
var express = require('express'),
exec = require('child_process').exec,
config = require('./config.json'),
bodyParser = require('body-parser');
var app = express();
app.use(bodyParser());
app.post('/deploy', function(req, res){
payload = JSON.parse(req.body.payload);
url = payload.canon_url + payload.repository.absolute_url;
config.list.forEach(function(item) {
item.url += !/\/$/.test(item.url) ? "/" : "";
if( item.url == url ) {
exec('git pull', {cwd: item.path}, function(error, stdout, stderr) {
if( error ) {
res.send('Error');
} else {
res.send('OK');
}
});
}
});
});
app.listen(9999, function() {
console.log('Listening on port %d', this.address().port);
});
{
"list": [
{
"url": "bitbucket url (e.g. https://bitbucket.org/greatdg/testproject/)",
"path": "pull path (e.g. /Users/greatdg/Workspaces/testproject"
}
]
}
{
"name": "bitbucket-post-hook",
"description": "",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "*",
"body-parser": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment