Gerrit as a review tool, not as the repository of record

后端 未结 1 1416
夕颜
夕颜 2021-02-13 06:48

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 Jenkin

相关标签:
1条回答
  • 2021-02-13 07:20

    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:

    1. A Gerrit user with direct push capabilities. For this, you'll need to grant Push privileges on the 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.
    2. A Jenkins job configured to build whenever new commits are pushed to your BitBucket repository. Within that job, simply push all branches to your Gerrit instance.
    3. Configure a BitBucket service hook to trigger your Jenkins build (for this, your Jenkins instance will need to be publicly accessible; otherwise simply set the schedule of your Jenkins job to a short interval to minimize the delay in synchronization).

    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):

    [remote "bitbucket"]
        url = ssh://git@bitbucket.org/<your-user>/${name}.git
        push = +refs/tags/*:refs/tags/*
        push = +refs/heads/*:refs/heads/*
        mirror = true
        replicateOnStartup = true
        replicatePermissions = false
    

    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!

    0 讨论(0)
提交回复
热议问题