Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Code review before checking in Bitbucket Server?

Song San May 24, 2018

  We are planning to get the Bitbucket Server software to install on one of our own server so we downloaded the trial version. One thing we want to do is to be able to put in requirements such as the code must be code-reviewed and unit test before can check in the code, which we believe Microsoft TFS have.  Is there similar settings in Bitbucket Server for the code review and unit testing and can you give me a link or steps to do this?

    I saw that Bitbucket Cloud Premium have the code review option at https://confluence.atlassian.com/bitbucket/bitbucket-cloud-premium-plan-856833380.html . is that also available in Bitbucket Server?

   

    Also saw an article of code review using Crucible and it seems like a separate software at https://www.atlassian.com/software/crucible. Is that another item that we need?

 

    Any  help would be greatly appreciated. I needed to make sure I have enough information so I can set up a demo and be able to let them know what software are needed and the pricing.

1 answer

0 votes
Mikael Sandberg
Community Champion
May 24, 2018

Yes, Bitbucket Server also allows you to set conditions on your Pull Request (code review) like all reviewers have to approve, minimal successful builds etc. Take a look at Checks for merging pull requests

You could use Crucible in conjunction with Bitbucket Server, it all depends on how formal you want your code reviews to be, check out this best practice, What's the difference between Crucible and Bitbucket Server? Do I need both? In most cases the pull request model in Bitbucket should be enough.

Song San May 25, 2018

Hi Mikael,

     Thanks for the reply. It seemed that this is a process in Bitbucket for Pull-requests. I don't see any customizable options exception from these 4 options (All reviewers approve, Minimum approvals, Minimum successful builds, No incomplete tasks). Don't see any option to add in unit testing and allow check-in after other processes are done such as Memory Analysis, etc.

      Currently we are using Microsoft TFS and some of our developers are using the code review and analysis checking prior to pushing their code to our development branch. Docs is at https://docs.microsoft.com/en-us/vsts/tfvc/add-check-policies?view=vsts and https://msdn.microsoft.com/en-us/library/dd264876.aspx .

        Bitbucket is a popular GIT repository and having code review, unit testing, etc seems to be standard processes so I am wondering if any other companies are implementing with Bitbucket and can provide information and instructions on how to do it.  Thanks

Mikael Sandberg
Community Champion
May 25, 2018

You can either create your own hooks for other processes like Memory Analysis, use Bamboo or Jenkins, or any of the many apps that integrate with Bitbucket. 

We are using Jenkins to do all of our builds and tests and is triggered once a user opens up a pull request. They are not able to complete the pr until all of our Jenkins jobs are successful.

Julius Davies [bit-booster.com]
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.
May 25, 2018

You can use the "Minimum successful builds" merge-check to make PRs block on analysis failures such as you mentioned, as long as you have a build script that fails on the same.  Setting the minimum threshold to 1 will still block the PR if ANY builds fail.

Despite its name, this merge-check causes ANY build failure to block the PR no matter how many builds are succeeding.  (The merge-check should be renamed to "NO FAILED BUILDS ALLOWED AND AT LEAST X NUMBER OF SUCCESSFUL BUILDS REQUIRED").

The "Sonar for Bitbucket Server" paid add-on is also really handy for blocking PR's based on static code analysis.

 

- Sylvie

(We maintain three paid add-ons:  1. Control Freak, 2. Git Graph for JIRA, 3. Rebase Squash Amend).

Song San May 29, 2018

Hi Mikael and Sylvie,

     Thanks for the suggestions. For Jenkins I had it configured to run a testing tool after the build and can also run some executable before the Jenkins build. But what I was asked to do is to put a requirement in Bitbucket to not allow check-in of the new update until the developer had their code review and their new code Unit test. So this would need to be something configured in Bitbucket to prevent this. I looked at the apps and Add-on and  couldn't find anything that would do it.

 

      Any other suggestions would be great.

Mikael Sandberg
Community Champion
May 29, 2018

You would then have to have a pre-commit hook in Bitbucket for it. But if the user is not allowed to commit anything on his/her branch before a code review, the only way to access the code change would be in the user's local repository.

The way we do it is that we allow users to commit code to their branches, but any code changes that will be merged into our integration branch has to be done via a pull request, and needs to be reviewed and approved before a merge to integration can be done.

Julius Davies [bit-booster.com]
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.
May 29, 2018

Exactly as @Mikael Sandberg mentioned:   staff push to some random branch (e.g., "TKT-2345"), and Bitbucket is configured to allow that.  But merging from TKT-2345 branch to master or release/* is only allowed via pull-request, which itself can require "minimum successful builds" (for the unit test) and "minimum approvals" (for the code review).  Both of those settings are available under "merge checks" for a given repo or project (collection of repos).

The paid Control Freak add-on my company maintains is handy for globally enforcing a mandatory "must use pull-requests" policy for master and release/* in a single place, or you can use Bitbucket's own "Branch Permissions" feature.

 

Here's a screenshot from Control Freak:

control-freak-config.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events