Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1171945
  • 博文数量: 312
  • 博客积分: 12522
  • 博客等级: 上将
  • 技术积分: 3376
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-27 18:35
文章分类

全部博文(312)

文章存档

2016年(3)

2015年(1)

2013年(1)

2012年(28)

2011年(101)

2010年(72)

2009年(13)

2008年(93)

分类: 项目管理

2011-06-03 09:46:41

Objective
  • Gerrit is a web based code review system, facilitating online code reviews for projects using the Git version control system.
  • Gerrit makes reviews easier by showing changes in a side-by-side display, and allowing inline comments to be added by any reviewer.
  • Gerrit simplifies Git based project maintainership by permitting any authorized user to submit changes to the master Git repository, rather than requiring all approved changes to be merged in by hand by the project maintainer. This functionality enables a more centralized usage of Git.
Download & Setup Gerrit  Prepare for installation
   $ wget http://gerrit.googlecode.com/files/gerrit-2.1.6.1.war

  
   If you would prefer to build Gerrit directly from source, review the notes under developer setup. (http://gerrit.googlecode.com/svn/documentation/2.1.6/dev-readme.html)

You can prepare the following required package in case they can not be downloaded at setup time. copy them to /review_site/lib/

   $ wget http://mysql.he.net/Downloads/Connector-J/mysql-connector-java-5.1.15.tar.gz  
$ wget http://downloads.bouncycastle.org/java/bcprov-jdk16-146.jar



Setup reviewdb in MySQL

      During init Gerrit supports: embeded H2, PostgreSQL, MySQL.(During init Gerrit will automatically configure the embedded H2 database. No additional configuration is necessary. Using the embedded H2 database is the easiest way to get a Gerrit site up and running.)
      Create a user for the web application within the database, assign it a password, create a database, and give the newly created user full rights on it:

 If you do not have mysql installed, use "sudo yum install mysql mysql-server mysql-libs mysql-devel", "service mysqld start", "mysqladmin -u root password '' " to install on rhel.

      === mysql

        CREATE USER 'git'@'localhost' IDENTIFIED BY 'git';
        CREATE DATABASE reviewdb;
        ALTER DATABASE reviewdb charset=latin1;
        GRANT ALL ON reviewdb.* TO 'git'@'localhost';
        FLUSH PRIVILEGES;


Initialize the Site

    Initialize a new site directory by running the init command, passing the path of the site directory to be created as an argument to the -d option. Its recommended that Gerrit Code Review be given its own user account on the host system:

   $ sudo adduser gerrit2 (or use : "useradd -m -G users -s /bin/bash gerrit2" make sure the groups you would like to join)
    $ sudo su gerrit2
    $ cd ~gerrit2

 Before you install gerrit, make sure your network works (need http_proxy?), or you download mysql driver and bcprov first and copy to lib directory after setup.

    java -jar gerrit.war init -d review_site
         *** Git Repositories -- [Default]
        *** SQL Database  -- [MySQL]
        *** User Authentication -- openAPI/http/https/[you can choose DEVELOPMENT_BECOME_ANY_ACCOUNT at development phase]
        *** Email Delivery -- [Go ahead with default, you can reconfigure them by editing /review_site/etc/gerrit.config file]
        *** SSH Daemon -- [Default]
        *** HTTP Daemon -- [Default]

 Now that you've reached this point you'll have Gerrit running a web application on port 8080, and listening for SSH connections on port 29418, congratulations! You're most of the way there

 To Start/Stop/Restart Gerrit site:

   $ /home/gerrit2/review_site/bin/gerrit.sh start



Setup Gerrit

 To control the Gerrit Code Review daemon that is running in the background, use the rc.d style start script created by init:

      $ review_site/bin/gerrit.sh start
      $ review_site/bin/gerrit.sh stop
      $ review_site/bin/gerrit.sh restart

 (Optional) Link the gerrit.sh script into rc3.d so the daemon automatically starts and stops with the operating system:

      $ sudo ln -snf `pwd`/review_site/bin/gerrit.sh /etc/init.d/gerrit.sh
      $ sudo ln -snf ../init.d/gerrit.sh /etc/rc3.d/S90gerrit
or $ sudo update-rc.d gerrit.sh defaults

 To install Gerrit into an existing servlet container instead of using the embedded Jetty server, see J2EE installation.[http://gerrit.googlecode.com/svn/documentation/2.1.6/install-j2ee.html]

 All Git repositories under gerrit.basePath must be registered in the Gerrit database in order to be accessed through SSH, or through the web interface.[http://gerrit.googlecode.com/svn/documentation/2.1.6/project-setup.html]

Create Project

From now on, you can start a project and code review from your workplace. 

SSH configuration

Each user uploading changes to Gerrit must configure one or more SSH public keys. The per-user SSH key list can be accessed over the web within Gerrit by Settings, and then accessing the SSH Keys tab.

At your client side, following the steps to create ssh public keys.

ssh-keygen -t rsa

Then copy the content of the public key file onto your clipboard, and paste it into Gerrit's web interface:

cat ~/.ssh/id_rsa.pub



Testing connection(To verify your SSH key is working correctly, try using an SSH client to connect to Gerrit's SSHD port.)

ssh -p 29418 sshusername@hostname

In the command above, sshusername was configured on the SSH Keys tab of the Settings screen. like the user name you use in gerrit, e.g. roger.   

Creating users and groups   

    First thing you should do after starting Gerrit up is log in to make sure your user is the administrator.
 
    After logging in with your favorite openID provider, Gerrit will allow you to enter in information about you (SSH key, email address, etc). It's worth noting that the email address is very important as Gerrit uses the email address to match your commits to your Gerrit account.
 
    When you create your SSH key for Gerrit, it's recommended that you give it a custom entry in ~/.ssh/config along the lines of:

    Host gerrithostname
          User roger
          Port 29418
          Hostname gerrithostname
          IdentityFile private/key> (e.g. ~/.ssh/id_rsa)


    Let's create a group for "integrators" that are responsible for reviewing code and integrating it into the "official" repository (typically integrators are project maintainers or core developers). Be sure to add yourself to the "Integrators" group, we'll use this "Integrators" group later to create more granular permissions on a particular project:
 

configure the gerrit web group rights as follows:

      Forge Identity
      Administrators
      refs/*  +2: Forge Committer or Tagger Identity



Create gerrit repository for projects Through SSH

Creating a new repository over SSH is perhaps the easiest way to configure a new project:

$ ssh -p 29418 changethisgerrithostname gerrit create-project --name appdemo

     

Notes: make sure the user you use should be in gerrit administrator group. For more, please refer:

http://gerrit.googlecode.com/svn-history/r6114/documentation/2.1.7/error-not-permitted-to-create.html

http://gerrit.googlecode.com/svn-history/r6114/documentation/2.1.7/error-permission-denied.html

    Then visit Admin > Projects and select "appdemo" and edited some of its permissions.

Add a "Remote" for Gerrit

clone project from gitorious

$ git clone git://changethisgitorioushostname/appdemo/appdemo.git

Gerrit Code Review provides a standard commit-msg hook which can be installed in the local Git repository to automatically create and insert a unique Change-Id line during git commit. To install the hook, copy it from Gerrit's SSH daemon:

$ cd appdemo
$ scp -p -P 29418 changethisgerrithostname:hooks/commit-msg .git/hooks/

Return to Git repository and add a "remote" for Gerrit, and push my master branch to it, This will give Gerrit a baseline for reviewing changes against and allow it to determine when a change has been merged down.(Here git.myserver.com is the gerrithost)

$ git checkout master
$ git remote add gerrithost ssh://git.myserver.com/appdemo.git
$ git push gerrithost master

If you can not do git push because of publickey problem, jump down to the following section for resolution method.

Create a branch and work on that branch and push for code review

      $ git checkout -b topic-branch
      $
      $ git commit
      $ git push gerrithost HEAD:refs/for/master

 The last command will push your commit to Gerrit. After the push is complete however, your changes will be awaiting review in Gerrit.
 

Notes: When do ‘git push’, it always report protocol error(expected sha/ref);

Then I changed the .git/config file to point the url of the repository using another way , it reports ‘Permission denied’ problem (publickey);

I tried to ssh-genkey and copy and save the key to gitorious, it still reports this error, I changed .git/config to point the url to ssh://git.myserver.com/appdemo.git, run ‘git push git.myserver.com HEAD:refs/for/master’, it reports: “you are not commiter” problem;

Then I run “git config –global user.email ” to set user, it still not works, finally I found that we have to configure the gerrit web group rights as follows:

Forge Identity

Administrators

refs/*  +2: Forge Committer or Tagger Identity

At this point, you'd likely wait for another reviewer to come along and either comment your code inline in the side-by-side viewer or otherwise approve the commit bu clicking "Publish Comments"
Gerrit contains a number of nice subtle features, like double-clicking a line inside the side-by-side diff to add a comment to that line specifically, the ability to "star" changes (similar to bookmarking) and a too many others to go into detail in this post.
After comments have been published, the view in My Dashboard has changed to indicate that the change has not only been reviewed but also verified.

Upon seeing this, I can return back to my Git repository and feel comfortable merging my code to the master branch:

     $ git checkout master
     $ git merge topic-branch
     $ git push origin master
     $ git push git.myserver.com master

     The last command is significant again, by pushing the updated master branch to Gerrit, we indicate that the change has been merged. Remember to add your ssh key to gitorious.

How to use gerrit-trigger with jenkins

Gerrit Trigger Plugin integrates Hudson to Gerrit code review for triggering builds when a "patch set" is created. 

(1).Download Gerrit Trigger from the website below:

 

You wil download a file named gerrit-trigger.hpi .

(2). Goto jenkins->Manage Jenkins->Manage Plugins->Advanced>Update plugins->Browse->Choose gerrit trigger plugin(gerrit-trigger.hpi)->Upload to install.

 

(3). Goto jenkins->Manage Jenkins ->Gerrit Trigger->Configure Gerrit Server as follows: (we use "jenkins" as the default user to do jenkins jobs) ->Test connections->save->click "start" in control panel. 


 
(3). Create a new job, like "GerritTriggerJob", of cause you can name it according to the project name. Configure the job as normal, and pay attention to the following options related to gerrit and git:
 
Builder Trigger: Gerrit Event
 
[Gerrit Trigger]
Gerrit Project: Type: plain; Pattern: appdemo;
Branches: Type: plain; Pattern: master
 
[Git repository]
URL of repository: ssh://gerrithost/appdemo.git
Refspec (blank to create default): $GERRIT_REFSPEC
Config user.name Value:
Config user.email Value:
Choosing strategy: Gerrit Trigger
 
(4). Modify codes and commit to gerrit host
 
(5). Check if you can trigger jobs manually? Jenkins->Query and Trigger Gerrit Patches>search by change id->Trigger selected
 
(6). Modify codes and commit to gerrit host and see if the created job in jenkins is triggered automatically.


git plugin download:

Refer posts:

 http://gerrit.googlecode.com/svn/documentation/2.1.6/install.html
 http://unethicalblogger.com/node/241

 

 

阅读(3250) | 评论(0) | 转发(0) |
0

上一篇:Perl 特殊符号含义

下一篇:perl笔记

给主人留下些什么吧!~~