Sonntag, 21. April 2013

POST Hook for GIT (Bitbucket.org)

I am recently messing around with GIT on my favorite site: Bitbucket.org.

As I was working on a website using GIT for the version control, I got tired by always pulling the recent changed onto the WebServer.

Just for the record: I am working on a local maschine with a test-environment and pulling all my pushes to the remote WebServer (LAMP).

What you can do is the following:

  • Create a Read-Only access to the Repository with a public-key pair. 
  • Add the public key as a deployment-key to your repository (Repository -> admin -> Deployment-Keys)
  • Pull your Repository to your WebServer via SSH
  • Change ownership of the git-folder (you pulled) to www-data (as this is the apache2 user)
  • Create a public accessable php script that executed a git pull 
  • Place a POST-hook to your php-pull-script on your Server (Repository -> admin -> Services -> POST)
A very basic git pull script could look like this:
<?php
$output = shell_exec('git pull');
echo "<pre>$output</pre>";
?>
 Now you should be done. I hope there is nothing I forgot :)

Questions -> ASK!; Mistakes -> TELL ME! :)

This is just some kind of note for myself. If its helpful for someone else: thumbs up!

3 Kommentare:

  1. hey men i know this post is old "but gold!" i folowed your steps but there shell_exec('git pull');
    is never getting fired bitbucket returns http code 200 but nothing happens ? any idea?

    AntwortenLöschen
  2. Is Bitbucket firing to the correct url? Maybe try to add a logger that logs if the url is really called.

    AntwortenLöschen
  3. New Man Titanium bracelet | Titanium-arts.com
    Tittanium-arts.com - Product of babyliss pro titanium straightener TITanium.com. Tetslip (1 x 1 inches). Tetslip black titanium fallout 76 (1 x 1 inches). Tetslip (1 x 1 inches). Tetslip (1 titanium wood stove x citizen super titanium armor 1 inches). Tetslip (1 x titanium hair trimmer as seen on tv 1 inches).

    AntwortenLöschen