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

烂漫一生 提交于 2019-12-03 10:32:32

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!