ironsand
ironsand

Reputation: 15171

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

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?

Upvotes: 7

Views: 5461

Answers (1)

Langusten Gustel
Langusten Gustel

Reputation: 11002

I did a very basic tutorial on this:

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

Upvotes: 6

Related Questions