How do I connect BitBucket Server with my project?

aweisbe1 August 30, 2017

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
Answer accepted
devpartisan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 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!

aweisbe1 September 1, 2017

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! 

aweisbe1 September 1, 2017

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

devpartisan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 1, 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.)

aweisbe1 September 1, 2017

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?

devpartisan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 1, 2017

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

aweisbe1 September 5, 2017

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.

devpartisan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 5, 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.

aweisbe1 September 5, 2017

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
TAGS
AUG Leaders

Atlassian Community Events