I've spun up an instance of gerrit from the quick start guide.
My company uses BitBucket with pull requests and occasionally crucible for code reviews. We use Jenkins with an extensive build/deploy pipeline tied to BitBucket.
We'd like to integrate gerrit for code review because of its ability to stage commits and build/verify them before the review is accepted.
Basically, I want gerrit's "submit" button to push upstream to BitBucket. (I'd rather not deal with trying to do this by replication; I want to maintain BitBucket as upstream/repository of record because of corporate inertia.)
Does anyone have any suggestions for how to accomplish this? Does the capability exist, or is this a novel idea?
Gerrit implements it's code review functionalities by providing a (more-or-less) thin wrapper around an actual Git repository that is hosted within Gerrit itself. To my knowledge, there is no possibility to integrate an external Git repository directly in Gerrit.
This means that when using Gerrit, the Git repository needs to be hosted within Gerrit itself. In consequence of that, you will need to maintain a full copy of your BitBucket repository within your Gerrit instance. So this question basically boils down to keeping two Git repositories in sync.
Synchronizing new commits from BitBucket to Gerrit
As you're already using Jenkins, I'd recommend a Jenkins build to update your Gerrit repository whenever new commits are pushed to the BitBucket repository. For this, you'll need:
refs/heads/*
ref in your Gerrit project. This user will be used by Jenkins. Be careful not to grant this privilege to any end-users, or they'll be able to bypass code review by pushing directly.Synchronizing new commits from Gerrit to BitBucket
When submitting code reviews in Gerrit, the new commits will need to be pushed back to BitBucket. Usually, I'd recommend using the replication plugin for that. Here's how a respective configuration file might look like (goes in
etc/replication.config
in your Gerrit directory):Since you mentioned that you'd like to avoid using replication, you can also use a Jenkins job for synchronizing commits from Gerrit back to BitBucket. To minimize the delay, you can use the Gerrit Trigger plugin for Jenkins (which you'll want to be using anyway for your pre-commit checks). Alternatively, you can use a custom Gerrit hook that you place in
hooks/ref-updated
to trigger a Jenkins build (drop a comment if you'd like me to elaborate on that).Hope this helps!