How can I deploy my bitbucket repo to my production server

tbobker February 22, 2017

I have git on my local computer where I am developing.  I can commit changes ..etc. and push those commits to bitbucket. 

But confused how am I supposed to then push these changes to my production server?  I tried init --bare on my servers local directory and pulling the repo but git didnt like it.

Ideally, I just want to push commits to Bitbucket from local computer and then push changes to production server.

What is the standard practice?

8 answers

14 votes
Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2017

I think that's what you want:

Develop locally and 1.) commit to your local repsoitory - 2.) push your local repository to your Bitbucket server - and 3.) have those pushes available on your production server

In this case Bitbucket Server holds your CENTRAL repository - every developer should push his changes to this server.  Everone who needs the CENTRAL repository (even your production server) should pull it from Bitbucket server.

For your production server you can either

1.) pull the repository manually

2.) 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  ...)

Summary: Your production machine has to be notified about "pushes" to central repository (by using a post-receive-hook within Bitbucket Server) - after getting the notification, your production server has to react correspondingly (for example by pulling the repository).

  

 

 

 

bradfranklin July 27, 2017

Nice! Thanks for sharing workflow. I'm not sure if I can setup the auto push alert to production server on my Media Server DV host. It's using the Plesk Panel and has a component install that can help set up a git connection.

The database sync confusing / stresses me out. May try it with a hello world wp install.

Like # people like this
muzammal ikram May 1, 2019

@Johannes Kilian  sir please guide me. I want to push my code on bit-bucket repository and server automatic pull from repository when i push to local to bit-bucket repo. Sir please Guide me??

1 vote
rglyall August 1, 2018

I'd recommend giving DeployHQ a try if you're looking for a solution with a nice UI. It's completely free if you've only got one project.

Sanjoy Roy April 11, 2019

thanks for your info.

Tom McCarthy August 11, 2019

Does DeployHQ deploy SQL code as well?, i.e. a SQL Repo with branches?

henryejemuta November 14, 2019

You'll have to do DB changes manually, as DeployHQ handles just files unless your SQL update would be within a script that you could run as webhook in similar manner Bitbucket informs DeployHQ of changes

1 vote
tbobker February 24, 2017

I went with the following solution. Please any comments on this appreciated:

 

  • on the server I run the following in the document root git clone myremotebitbucketrepo
  • once I updated my git locally and pushed commits to my Bitbucket repo
  • on the server I run git pull

 

heypressgo March 16, 2018

Does this process work for you?

Like jhorning-tyler likes this
1 vote
Christian Glockner
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 22, 2017

Hi Tim,

Bitbucket is the central point here, that's where your code lives. You clone your repo from Bitbucket to your workstation, make the changes and push the changes back to Bitbucket. Once you have code that you think is ready for primetime you'd clone the repo onto your production server (or pull changes if you've cloned the repository already).

Cheers,

Christian

Premier Support Engineer

Atlassian

chanduravula October 2, 2018

hi guys,

           can anyone tell me the how to generate ear from bitbucket code repository.i'm using pipelines with maven.but i didn't get any jar and war files in my ear content.is there any plugin for converting module to ear.please suggest me.

pixelliquid February 3, 2020

Hi Christian - or anyone with the Premier Support Engineer status :)

Your answer is exactly what the question was in the first place, but it doesn't say how . Unfortunately I'm stuck as well and the settings of my repo in Bitbucket is not helpful - do I need to put in Access keys, a Webhook, or Pipeline with SSH keys?

0 votes
Scott Taylor July 30, 2019

I have been searching for a more "elegant" solution, using hooks.  However, we are using Windows, and I came up with a down-and-dirty solution that, while requiring some tweaking from time to time, has been working for us.

Our developers develop locally, and push to Bitbucket Server.  Our next hop is to internal development "test" servers.  I have project-specific repositories on those servers, "pull" scripts for each project, and project-specific scheduled tasks in Windows Task Scheduler.  The tasks run on 1-minute intervals.  This process is reliable 95+ percent of the time, as there is a problem where, after days, weeks, months of working, the tasks stop running.  Re-entering the trigger time and date corrects the issue.

This flaw is why I would like to find a more"push" oriented solution.  My hang-up is the configuration of what I have seen described (including above) as "a little web server, waiting for this HTTP-Request."  I know how to configure IIS, but cannot find details on the rest of the setup.

Inertia ("hey, it works good enough...") is making this a lower priority, but I would like to make this work, as we would ultimately like to have a form of automated deployment up to and including production.

0 votes
Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2017

You shouldn't use git init --bare since option bare is a "special" option for repository servers (see for example: http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/) - and you don't want to be your production machine to be a repository server (Bitbucket server uses bare repositories - as this is a repository server)

You cannot checkout from a bare repository - you are only able to clone it. (as far as I understood git)

So: just omitt the option --bare and try it again ...

Fidelis Inaku February 9, 2018

Hello Johannes,

I am new to using Bitbucket and will appreciate a step by step setup for the answer you gave to Tim's question above. I am having same problem and would like to achieve the workflow you stated. I am grateful for any help.

heypressgo March 16, 2018

This is a great discussion. As I'm also wanting the same flow as Tim has mentioned. 

UK Print and Promotions Ltd May 25, 2018

James, did you get this working? I’ve tried a month or 2 back trying to setup pipelines but couldn’t make it work 

Fidelis Inaku May 26, 2018

Hello UK Print and Promotions Ltd,

This actually worked for me

https://jonathannicol.com/blog/2013/11/19/automated-git-deployments-from-bitbucket/

Like Jieming Hu likes this
0 votes
tbobker February 22, 2017

Thanks for all the answers.  So if I need to do a pull from my production server (I prefer manual) then the following should have worked:.  Git init --bare then git add remote origin (link to bitbucket repository) then git pull --all. But this doesn't work?  Error not branch found 

 

 

 

 

 

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2017

What do you mean when you say you are able to push to bitbucket? Which instance is that, if that is not the production one?

Are you talking about the local repository? 

tbobker February 22, 2017

I am talking about committing locally and then a push to origin at Bitbucket repository.

Want I want to do is once I am happy with changes locally I want to push all the changes to my staging environment on a server.

I thought I could just pull the updated Bitbucket repository from my staging server but doesnt work.

bradfranklin July 27, 2017

I'm trying to set up the same type of workflow, just came across this link. Thought I'd share it. Hope it helps

https://premium.wpmudev.org/blog/improve-wordpress-development-workflow-local-server/

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events