Jump to: navigation, search

Gerrit Workflow

Revision as of 16:18, 25 July 2011 by JamesBlair (talk)


#!wiki caution
'''Note'''

This workflow for developers is a work in progress and is not ready
for use by OpenStack projects.  Please see [[LifeWithBzrAndLaunchpad]]
for current project practices.


<<TableOfContents()>>

Gerrit, Jenkins, and GitHub Workflow

GitHub is a resource for managing Git code repositories and interacting with other developers. Jenkins is used to continuously test all of the components of OpenStack to ensure functionality and to verify that each change to the code base works as intended. Gerrit is a code review system originally developed for use by the Android Open Source Project and allows us to build a workflow where every change is peer-reviewed and tested by Jenkins before being merged into the main repository.

After making a change in their local Git repository, developers can easily push that change to Gerrit as a proposed change for the project. Jenkins will automatically run functional tests on the code and provide feedback on the change in Gerrit. Any OpenStack developer can provide feedback (in the form of a comment, or even line-by-line annotations) using Gerrit, and the core developers of the project can indicate whether they approve of the patch as is, or would like to see changes before it is integrated. Once patches are merged by Gerrit, the repository is pushed to the canonical public repository on GitHub.

Using Gerrit

The next sections will describe what steps a developer should take to use Gerrit as part of this workflow.

Gerrit Accounts

Visit https://review.openstack.org/ and click the Sign In link at the top-right corner of the page. Log in with your Launchpad ID.


#!wiki caution
'''Note'''

The OpenStack Gerrit site currently uses a self-signed SSL
certificate; this will be replaced with a certificate from a 
recognized CA soon.


Because Gerrit uses Launchpad OpenID single sign-on, you won't need a separate password for Gerrit, and once you log in to one of Launchpad, Gerrit, or Jenkins, you won't have to enter your password for the others.

Gerrit accounts are automatically synchronized with Launchpad, so your Gerrit account should already have the same username, full name, email address, ssh keys, and group membership.

Some information in Launchpad is not publicly available and so may not be copied over. The first time you log into Gerrit, you should click the Settings link at the top of the page, and then make sure that your Contact Information, SSH Public Keys, and Groups look correct. If not, please register your email address and SSH keys. If your group membership is not correct, please email openstack-ci-admins@lists.launchpad.net.


#!wiki caution
'''Note'''

For each project you contribute to, you will want to make Gerrit notify you of changes to the project's master repo. To do so, you will want to go to https://review.openstack.org/#settings,projects and enter the names of projects to watch.


Cloning a Git Repository

Clone a copy of the repository for the OpenStack project you want to work on from GitHub using a command similar to the following:


git clone git://github.com/openstack/PROJECT.git


Or if you have a GitHub account, via SSH:


git clone git@github.com:openstack/PROJECT.git


Where PROJECT is the name of the project you want to work on. The correct path to use can also be found on the project's page on GitHub.

Setting up Git for Use with Gerrit

For a more comprehensive look at using Gerrit, see the Gerrit manual.

Change-Id Hook

Gerrit adds a Change-Id header to commits so that it can link Git commits to changes stored in its database. It will add it automatically if not present, but frequent Gerrit users may want to have the header added locally before being uploaded to Gerrit. In particular, this will make updating patches for existing changes easier. To cause the Change-Id header to be added automatically to each commit message, run this command inside your repository:


scp -p -P 29418 USERNAME@review.openstack.org:hooks/commit-msg .git/hooks/


Where USERNAME is the username you registered with Gerrit.

Pushing Changes from Git

To make pushing proposed changes to Gerrit easier, you may register Gerrit as a remote repository tracked by Git. Run the following command inside your local Git repository:


git remote add gerrit ssh://USERNAME@review.openstack.org:29418/openstack/PROJECT.git


Where USERNAME is the username you registered with Gerrit and PROJECT is the name of the current project. Then when you are ready to push a change to Gerrit for review, you may issue a command like:


git push gerrit HEAD:refs/for/master


If you find that you do not enjoy typing git push gerrit HEAD:refs/for/master, you can add a git alias. Edit your ~/.gitconfig file and add an alias like this:


[alias]
        review = push gerrit HEAD:refs/for/master


From then on, pushing a change to gerrit is as simple as:


git review


Git SSH Commands

If you find you are frequently executing Gerrit commands via SSH, you may wish to add something like the following to your ~/.ssh/config file:


Host review
  Hostname review.openstack.org
  Port 29418
  User USERNAME


Which may shorten some SSH commands; the following are equivalent:


ssh -p 29418 review.openstack.org gerrit ls-projects
ssh review gerrit ls-projects


Reviewing a Change

Log in to https://review.openstack.org/ to see proposed changes, and review them. Any Openstack developer may propose or comment on a change (including voting +/-1 on it). Members of the core project team may mark changes as approved (by voting +2), which will immediately cause Jenkins to verify the change. If Jenkins successfully tests the change, and there are no -2 code review votes, the change will be automatically merged into the repository.

Resources

See the Gerrit documentation, especially the User Guide, for more information on how to use Gerrit. It is also available within Gerrit by clicking on the Documentation link on the top of the page.

The Mahara Project also uses Git, Gerit, and Jenkins in a similar manner (though with Gitorious instead of GitHub).