How do I connect BitBucket Server with my project?

I am new to BitBucket Server and wonder about the relationship between BitBucket Server and my actual project. I have BitBucket Server installed on my web server (where my development project lives) and have successfully connected to BitBucket Server from SourceTree, committed and pushed, etc. 

What I don't understand is what I do next. I'd like that when I commit to my BitBucket Server repository, that updates the project development environment on the web server. With Git, I would just have the remote repository live in the folder on the web server where my project resides. How do I tell BitBucket Server to 'live' there? 

Do I need Bamboo to accomplish this? I see that there is a Source Code Checkout task there. Or am I simply misunderstanding the workings of BitBucket Server? 

All guidance is appreciated. 

Thank you. 

1 answer

1 accepted

0 votes
Accepted answer
Ian Buchanan Atlassian Team Aug 30, 2017

As you've discovered, Bitbucket Server doesn't work like "naked" Git. It's meant to be the home for many collaborators and many repositories. As such, it does "own" where it stores Git repositories. A while back, I wrote a blog post about triggering deployment with Git commands that might address your needs.

Yes, you could add Bamboo to the mix, especially if you have some form of tests you would want to run before deploying to your web server.

One more option you might consider would be to skip running your own Bitbucket Server, and use Bitbucket Cloud. Then you could leverage Bitbucket Pipelines to push your web code to your web server.

Hope that helps!

Thanks for your prompt response! Would it work just as well to use the Mirror Hook and just mirror the repo to a Git directory in my directory each time someone commits? 

Also, any idea how to test hooks? 

 

Thank you! 

We can't skip running BitBucket Server since we need to run this on our own private server which is behind enterprise networks. 

Ian Buchanan Atlassian Team Sep 01, 2017

Yes, Bitbucket Server is the right fit for enterprise networks. Say no more.

The Mirror Hook sounds like the perfect solution. Sorry I had missed that. You should also be able to find the Mirror Hook as an add-on listed on the Marketplace:

https://marketplace.atlassian.com/plugins/com.englishtown.stash-hook-mirror/server/overview

As for testing, I would be more worried about monitoring. It's trivial to verify the result of a mirror once. But I think it's more interesting to know if a mirror has failed due to a network disruption or something. I think the easy approach is to wire your remote Git server (the web server) with a Git post-receive hook to call back to Bitbucket on every mirrored commit. I think something like this should work:

https://bitbucket.org/ian_buchanan/bitbucket-server-mirror-monitor-hook/src/master/post-receive?fileviewer=file-view-default

(Sorry, it's untested code, but shoot me a pull request if you find a serious error.)

Thank you so much for all your help. Any idea how to test if a hook 'worked'? Similar to testing that a Bamboo build was successful?

Ian Buchanan Atlassian Team Sep 01, 2017

Yup, that's the point of the post-receive hook. To send a "green build" back to Bitbucket when each commit gets mirrored.

Hmm. But how do I set it up to send back a "green build"? I currently have the hook set up but don't see it working and get no feedback of whether it works or not...? Thank you so much for all your help.

Ian Buchanan Atlassian Team Sep 05, 2017

It could be my error. I assumed you're running in a Bash world, not Windows. More importantly, I just removed `/bitbucket` from the start of the API URL path (if your Bitbucket is configured on a subpath, then include it in the BITBUCKET_URL, and make sure not to use a trailing slash) and added the `--verbose` switch to help with debugging.

Before configuring the hook, try putting some static values in for LAST_COMMIT_SHA (it must be the 40 char hash, not an abbreviation as found in the Bitbucket UI) and LAST_COMMIT_MESSAGE. Then you should be able to just run the script. After the URL fix, it works for me. On the command line, the script (now with verbose setting) should return an HTTP 204 response.

Once you find it working "manually", then you can configure the hook according to standard Git instructions.

Sorry- to clarify, I meant that I have the Mirror Hook set up. How do I get a status message from it?

 

Thank you very much!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

239 views 3 7
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you