Created
May 30, 2014 07:05
-
-
Save greatdg/4d126c51dbe7413f6808 to your computer and use it in GitHub Desktop.
automated deployment from bitbucket using post hook
This file contains 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
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); | |
}); |
This file contains 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
{ | |
"list": [ | |
{ | |
"url": "bitbucket url (e.g. https://bitbucket.org/greatdg/testproject/)", | |
"path": "pull path (e.g. /Users/greatdg/Workspaces/testproject" | |
} | |
] | |
} |
This file contains 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
{ | |
"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