7

I develop my code locally, commit it to my local repsoitory and then push it to my Bitbucket server. After that I have to login via ssh to my production server like this:

ssh my-server@my-host.de
pass: very-secure-passs
cd www/myPage
cd git pull origin master
pass: very-secure-pass 

I would like to avoid login to my production server and let him pull automatically.

I want to have 3 repositories (local, BitBucket and production Server), so I cant use this solution: Do an automatic pull request after pushing to server

I found this question A hook that let `pull` from VPS when I `push` to Bitbucket which is exactly what I want, but it is from 2013 and the answer is outdated since BitBucket has changed since then.

I found here https://community.atlassian.com/t5/Answers-Developer-Questions/How-can-I-deploy-my-bitbucket-repo-to-my-production-server/qaq-p/565348 that someone suggested to use a free Plugin called HTTP-Request Hook for Bitbucket Server

set up an automated "Pull": Each time you do a push to your central repository, your production machine is notified and pulls the repository on notification. Bitbucket Server offers serval plugins to support the notification process - the one I use is Http Request Post Receive Hook: each time a push is made, a configured URL is contacted, submitting some info. On my production machine I have set up a little web server, waiting for this HTTP-Request. On receiving the HTPP-Request I evaluate the given parameters and perform an action (for example: pulling the repository ...)

Now my questions are:

  1. Is it possible to use a Webhook instead of the HTTP-Request Hook Plugin?

  2. How should the file on my production server look like so that it will do a pull request when it receives a HTTP-Request? I would be interested in a basic example in PHP.

Adam
  • 25,960
  • 22
  • 158
  • 247
  • 1
    If your production server provides `ftp`, maybe you can solve your problem with [`git-ftp`](https://github.com/git-ftp/git-ftp) which states: *Git-ftp -- uploads to FTP servers the Git way*. This means that after you `git push` you will have to also `git ftp push` and your production environment will be updated. See: [Git Push into Production (FTP)](https://stackoverflow.com/questions/2950107/git-push-into-production-ftp) – tgogos Jan 31 '18 at 09:17
  • You should look forward to jenkins (http://jenkins.io/). Your keywords are "Continuous Integration" and "Continuous Delivery". There are some very nice tools around so you dont have to do anything manually. – Spears Feb 01 '18 at 06:56

2 Answers2

4

The webhook documentation you linked is for Bitbucket Cloud (bitbucket.org), not Bitbucket Server (which is self-hosted and has some other URL). If you're using BB Cloud, then the HTTP-Request Hook Plugin won't work, but the documentation you linked will. If you're using BB Server, then you can use https://confluence.atlassian.com/bitbucketserver/managing-webhooks-in-bitbucket-server-938025878.html instead to define a webhook.

For the second half of your question - how to set up your server's end of a webhook - you'll need to have a small service that listens for the incoming webhook, does whatever authentication you want, and then runs your pull method. There are a zillion ways to do this, but most will vary based on your preferred language and security settings and on the network configuration of the server in question. I'd suggest a Google search for "webhook deploy $LANGUAGE" to see how some others have done it with your preferred language, or to see if there's a public repo or gist or snippet out there that you can use.

Jim Redmond
  • 4,139
  • 1
  • 14
  • 18
  • Whoups, yes that link was wrong. I have a BB Server. I would like to have the script written in PHP with SSH keys. Is it possible to write something like this with a few lines? Anyway, I found https://github.com/markomarkovic/simple-php-git-deploy/ and I will read it in more detail in the next days. Thanks for your answer! – Adam Jan 26 '18 at 10:27
0

Instead of directly trying to pull on production server, you can setup a Jenkins job that will push the code to production server on each commit. Using Jenkins you can even customize the solutions to match particular token in commit message.

Tapas
  • 1,123
  • 8
  • 16