Gerrit管理帐号

文档

Gerrit服务器启动后,网站上有一个Documentation链接。点击后会看到四个选项:

index,searching,uploading和access control

文档内容很多,不必专门去Gerrit官方查找。

 

创建CI服务器使用的帐号

CI服务器比如Jenkins肯定需要访问Gerrit来获取最新的源代码进行编译。

1.你必须在管理员所在的客户端执行命令。也就是说,你执行命令的本地机器已经作为管理员加入到Gerrit系统中。

2.将CI服务器上的公钥文件拷贝到本地机器上,假定放在了~/目录下

3.执行命令,创建帐号

1
cat ~/id_rsa.pub | ssh -p 29418 your_server gerrit create-account --group your_group --full-name usa1 --email your_email --ssh-key - usa1

提示:

gourp name如果包含空格,应该用引号包起来,并且用\引导。比如:

1
create-account --group 'Build\ Users'

- -ssh-key 参数后用 - 表示从标准输入获取公钥内容,这里最开头用了cat ~/id_rsa.pub | 方式刚好提供了所需。

email和用户名不允许和已有用户重复,但是公钥允许重复。

4.到CI所在服务器上,用命令clone项目。

1
git clone ssh://usa1@your_server:29418/your_project.git



查询和删除帐号


需要到数据库中查找和删除。没有其他途径。

如果使用的是H2数据库,确保Gerrit服务启动的情况下,使用下面的命令就可以登录远程数据库。(之前我弄错了端口号,其实真的很简单)

1
ssh -p 29418 user@my_server gerrit gsql

如果当前登录的Linux用户名和Gerrit上注册的用户名不一样,需要在参数中指明正确用户名。比如:

1
ssh -p 29418 shuchen@my_server gerrit gsql

 

 

或者直接登录gerrit服务器,关闭gerrit服务后,用下面的命令启动:

1
java -jar gerrit-2.3.war gsql -d ./review_site/

 

修改用户名

1
update ACCOUNT_EXTERNAL_IDS set external_id='username:chenshu' where external_id='username:shuchen';

 

上面的sql语句将用户名从shuchen换成了chenshu

 

数据库操作问题1:

    最近发现增删账号等数据库操作的要求越来越频繁,而通过ssh gerrit gsql进入数据库操作还是比较繁琐的。

    查找Gerrit Document会发现有如下用法:

ssh -p <port> <host> gerrit gsql
  [--format {PRETTY | JSON}]
  [-c QUERY]

    尝试一条简单的命令ssh -p 29418 server gerrit gsql -c "select * from accounts"

报错: fatal: No argument is allowed: *

    尝试一条简单的命令ssh -p 29418 server gerrit gsql -c "select ALL from accounts"

报错: fatal: No argument is allowed: ALL

 

知识有限,暂时没辙了。果断挂代理上google,得到如下结果:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
On Wed, Aug 10, 2011 at 4:43 PM, bruce zu <zu.bruc...@gmail.com> wrote:
Hi  , Dear All
 
 my colleague find  gerrit  sshd function about  gsql  not good
enough , I check it and find
  
It is not about gsql function but about quoting the command properly in your shell which can be tricky.
  
 
       ssh <name>@<host> -p 29419 gerrit gsql -c "select * from
accounts"
have you tried:
 
ssh <name>@<host> -p 29419 gerrit gsql -c \"select \* from accounts\"
You need to backslash the *, otherwise the shell will glob it and replace with all files in the current folder.
 
  
 
   can not work , gerrit will say  it will not support '*'.
 
       ssh <name>@<host> -p 29419 gerrit gsql -c "select full_name
from accounts"
 
ssh <name>@<host> -p 29419 gerrit gsql -c \"select full_name from accounts\"
 
   
 
   can not work , gerrit will say  full_name is not a column name.
 
    ssh <name>@<host> -p 29419 gerrit gsql -c "SELECT FULL_NAME  FROM
ACCOUNTS"
 
   can not work , gerrit will pending there  and without giving any
error or other information after I waiting it for more than half an
hour.
I don't understand how is this different than the previous example with lowercase SQL string.
Anyway, if it hangs then create a thread dump of the Gerrit process and see if there are any threads
waiting in a JDBC driver call. If yes, then your database is not responding... or not responding quick enough.
 
Sasa Zivkov

结果很明了,要用ssh Server gerrit gsql -c \"select \* from accounts\"

一般情况下删除一个账号需要用到如下command:

ssh 3188 gerrit gsql -c \"select \* from accounts where preferred_email=\'James_Bond@xxx.com\'\"
1000274 1000766

ssh 3188 gerrit gsql -c \"delete from ACCOUNTS where account_id=1000766\"
ssh 3188 gerrit gsql -c \"delete from ACCOUNT_EXTERNAL_IDS where account_id=1000766\"
ssh 3188 gerrit gsql -c \"delete from ACCOUNT_GROUP_MEMBERS where account_id=1000766\"
ssh 3188 gerrit gsql -c \"delete from ACCOUNT_GROUP_MEMBERS_AUDIT where account_id=1000766\"
ssh 3188 gerrit gsql -c \"delete from ACCOUNT_GROUP_NAMES where account_id=1000766\"
ssh 3188 gerrit gsql -c \"delete from ACCOUNT_SSH_KEYS where account_id=1000766\"

 

百度空间太坑爹了,自今天其全面转移到博客园。。。

附原链接http://hi.baidu.com/hengbo0926/item/d65b33c23d07f22ea0b50ac0

posted @ 2014-09-02 10:36  梦溺残沙里  阅读(4773)  评论(0编辑  收藏  举报