Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A hook that let `pull` from VPS when I `push` to Bitbucket

Tags:

git

I'm managing my wordpress template in Bitbucket.

Each time I push the theme, I must log in my VPS server and pull the repo. I want to do it automatically.

I found a solution if I run git deamon myown. Do an automatic pull request after pushing to server

But I want to use Bitbucket because it works as a backup also.

I found a Document about bitbucket's hook, but I could't find how to do it. https://confluence.atlassian.com/display/BITBUCKET/Manage+Bitbucket+hooks

Could anyone show me a solution?

like image 681
ironsand Avatar asked Oct 21 '13 21:10

ironsand


1 Answers

I did a very basic tutorial on this:

  • http://jan1337z.blogspot.de/2013/04/post-hook-for-git-bitbucketorg.html

this basic steps are:

  1. Create a Read-Only access to the Repository with a public-key pair.
  2. Add the public key as a deployment key to your repository (Repository -> Settings -> Deployment keys)
  3. Pull your Repository to your WebServer via SSH
  4. Change ownership of the git-folder (you pulled) to www-data (as this is the apache2 user)
  5. Create a public accessable php script that executed a git pull
  6. Place a POST-hook to your php-pull-script on your Server (Repository -> admin -> Hooks -> POST)

Cant find admin?
while you are on your repository (on bitbucket) its the gearwheel in the top right. Either click on it or type 'r' and then 'a'.

Basic PHP script to make the pull:

<?php
    $output = shell_exec('git pull');
    echo "<pre>$output</pre>";
?>

I had this running just to proof that it is possible. Improve it :)

How to create a deployment key (step 2): enter image description here

like image 162
Langusten Gustel Avatar answered Oct 12 '22 23:10

Langusten Gustel