Gerrit和Gitlab服務器的集成
作者:尹正傑
版權聲明:原創作品,謝絕轉載!否則將追究法律責任。
一.安裝gitlab
詳情請參考:https://www.cnblogs.com/yinzhengjie/p/9568657.html
二.在Gitlib上創建項目
1>.點擊"New Project"
2>.自定義項目名稱
3>.項目創建成功,點擊README鏈接
4>.編輯REDEME文件
5>.文件添加成功
三.Gerrit創建同名的項目
1>.點擊存儲庫
2>.點擊"CREATE NEW"
3>.點擊"CREATE"
4>.項目創建成功
四.在Gerrit服務器上克隆代碼到本地
1>.在Gerrit生成密鑰
[root@gerrit.yinzhengjie.org.cn ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa Generating public/private rsa key pair. Created directory '/root/.ssh'. Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:9ROz1CLGzbskWd0nvJMc1jfgmOez8Lpm7kcz1YjSb7k root@git.yinzhengjie.org.cn The key's randomart image is: +---[RSA 2048]----+ | . | | . o++.o | | =+O+Bo*| | o.*=O.*=| | S oo*+*. | | oo**. | | o+o. | | o..E | | ==o | +----[SHA256]-----+ [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+28LdoSvWfllJVfD0OdWV4ku3bIO5u/AtatQJrYhBifIWnWa2WnIQggz6/KIBWF/QCJHzGaPpZrjVzvPnJaDMwaQNFIutSPchob/HebQ7SRI09a1xRHCYZ3hJzSvaYLDrOt41HHAW2gTTmWMQTMtnX0ZZpst6HHwHluCqWCX6j7uNK2jDgOfGxC4RzbR6bVVYsZ2vN+6BvFyrfHL5wUBsIwKBxgfuHj+a0+i6LJtfyqkom/VTLEtvCnizBw41UMPm/rlH5rBIfE52qjrFqgqg2d9Uaz6st7stmguToPwCHjGUPqJVKk2Cf8JaHUOXsP8o73gXESbe9GSZEgqtpapd root@git.yinzhengjie.org.cn [root@gerrit.yinzhengjie.org.cn ~]#
2>.將公鑰拷貝到gitlab上
3>.將公鑰拷貝到Gerrit上
4>.將gitlab的代碼克隆到本地
[root@gerrit.yinzhengjie.org.cn ~]# cd /yinzhengjie/softwares/gerrit/ [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# ll total 0 drwxr-xr-x 7 root root 119 Jun 25 03:27 All-Projects.git drwxr-xr-x 7 root root 119 Jun 25 03:33 All-Users.git drwxr-xr-x 7 root root 100 Jun 25 05:13 yinzhengjie_code.git [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# rm -rf yinzhengjie_code.git #先將Gerrit創建的同名項目刪除 [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# ll total 0 drwxr-xr-x 7 root root 119 Jun 25 03:27 All-Projects.git drwxr-xr-x 7 root root 119 Jun 25 03:33 All-Users.git [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# git clone --bare git@gitlab.yinzhengjie.org.cn:root/yinzhengjie_code.git #然后把gitlab的項目克隆到Gerrit的目錄中 Cloning into bare repository 'yinzhengjie_code.git'... The authenticity of host 'gitlab.yinzhengjie.org.cn (172.30.1.80)' can't be established. ECDSA key fingerprint is SHA256:dxYzHaEpkoSjSE0UDEtz14Y4dCn+GX3HJZ+P8AzsF54. ECDSA key fingerprint is MD5:f6:a9:3b:12:2c:44:2f:e3:d7:2f:0b:fb:b2:33:4f:99. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'gitlab.yinzhengjie.org.cn,172.30.1.80' (ECDSA) to the list of known hosts. remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]# ll total 0 drwxr-xr-x 7 root root 119 Jun 25 03:27 All-Projects.git drwxr-xr-x 7 root root 119 Jun 25 03:33 All-Users.git drwxr-xr-x 7 root root 138 Jun 25 05:55 yinzhengjie_code.git [root@gerrit.yinzhengjie.org.cn /yinzhengjie/softwares/gerrit]#
5>.客戶端克隆Gerrit的代碼(同理,客戶端需要把公鑰內容上傳到Gerrit服務器)
[root@git.yinzhengjie.org.cn ~]# git clone "ssh://admin@gerrit.yinzhengjie.org.cn:29418/yinzhengjie_code" #我們在客戶端把Gerrit的項目克隆到本地 Cloning into 'yinzhengjie_code'... The authenticity of host '[gerrit.yinzhengjie.org.cn]:29418 ([172.30.1.81]:29418)' can't be established. ECDSA key fingerprint is SHA256:LfFtLE0id3OuNcGSZokcrCFCv9HxzJtS8xIqLWw+SIM. ECDSA key fingerprint is MD5:23:ae:2d:04:52:75:82:87:ef:7f:44:73:87:5c:45:0a. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[gerrit.yinzhengjie.org.cn]:29418,[172.30.1.81]:29418' (ECDSA) to the list of known hosts. remote: Counting objects: 3, done remote: Finding sources: 100% (3/3) remote: Total 3 (delta 0), reused 3 (delta 0) Receiving objects: 100% (3/3), done. [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# ll total 0 drwxr-xr-x 3 root root 35 Jun 25 06:02 yinzhengjie_code [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# ll yinzhengjie_code/ total 4 -rw-r--r-- 1 root root 41 Jun 25 06:02 README.md [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# more yinzhengjie_code/README.md #查看我們聰Gerrit服務器下載的代碼,其內容和Gitlab數據是一致的。 BLOG:https://www.cnblogs.com/yinzhengjie/ [root@git.yinzhengjie.org.cn ~]#
五.配置Gerrit和Gitlab互信
1>.在Gerrit服務器上配置和Gitlab互信
[root@gerrit.yinzhengjie.org.cn ~]# ssh-copy-id root@gitlab.yinzhengjie.org.cn /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@gitlab.yinzhengjie.org.cn's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@gitlab.yinzhengjie.org.cn'" and check to make sure that only the key(s) you wanted were added. [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# ssh gitlab.yinzhengjie.org.cn Last login: Tue Jun 25 02:31:58 2019 from 172.30.1.1 [root@gitlab.yinzhengjie.org.cn ~]# [root@gitlab.yinzhengjie.org.cn ~]# who root pts/0 2019-06-25 02:31 (172.30.1.1) root pts/1 2019-06-25 06:09 (172.30.1.81) [root@gitlab.yinzhengjie.org.cn ~]# [root@gitlab.yinzhengjie.org.cn ~]# logout Connection to gitlab.yinzhengjie.org.cn closed. [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]#
2>.在Gitlab上配置和Gerrit互信
[root@gitlab.yinzhengjie.org.cn ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa Generating public/private rsa key pair. Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:vlO7fU06xQYclRWDbjs6hKCp/zX+OSCSh6gLFJBDpPY root@gitlab.yinzhengjie.org.cn The key's randomart image is: +---[RSA 2048]----+ |++ .+*| |= ....| |.+ .. . | |. o . oo | | . E. = S . . .o | |. . * + o.. o =| |. . . o o+o.. .* | |.. . +.o=. + .| | .. .....oo++. . | +----[SHA256]-----+ [root@gitlab.yinzhengjie.org.cn ~]# [root@gitlab.yinzhengjie.org.cn ~]# [root@gitlab.yinzhengjie.org.cn ~]# ssh-copy-id gerrit.yinzhengjie.org.cn /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'gerrit.yinzhengjie.org.cn (172.30.1.81)' can't be established. ECDSA key fingerprint is SHA256:dxYzHaEpkoSjSE0UDEtz14Y4dCn+GX3HJZ+P8AzsF54. ECDSA key fingerprint is MD5:f6:a9:3b:12:2c:44:2f:e3:d7:2f:0b:fb:b2:33:4f:99. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@gerrit.yinzhengjie.org.cn's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'gerrit.yinzhengjie.org.cn'" and check to make sure that only the key(s) you wanted were added. [root@gitlab.yinzhengjie.org.cn ~]# [root@gitlab.yinzhengjie.org.cn ~]# ssh gerrit.yinzhengjie.org.cn Last login: Tue Jun 25 03:28:02 2019 [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# who root pts/0 2019-06-25 02:31 (172.30.1.1) root pts/1 2019-06-25 03:26 (172.30.1.1) root pts/2 2019-06-25 06:12 (172.30.1.80) [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# logout Connection to gerrit.yinzhengjie.org.cn closed. [root@gitlab.yinzhengjie.org.cn ~]# [root@gitlab.yinzhengjie.org.cn ~]#
六.在Gerrit服務器上編輯同步Gitlab的配置文件
1>.編輯 “review_site/.ssh/config”配置文件,需要手動創建(同步gitlab的項目用的)
[root@gerrit.yinzhengjie.org.cn ~]# ll review_site/etc/ total 52 -rw-r--r-- 1 root root 788 Jun 25 03:27 gerrit.config drwxr-xr-x 2 root root 4096 Jun 25 03:27 mail -rw------- 1 root root 99 Jun 25 03:26 secure.config -rw------- 1 root root 288 Jun 25 03:26 ssh_host_ecdsa_384_key -rw-r--r-- 1 root root 250 Jun 25 03:26 ssh_host_ecdsa_384_key.pub -rw------- 1 root root 365 Jun 25 03:26 ssh_host_ecdsa_521_key -rw-r--r-- 1 root root 298 Jun 25 03:26 ssh_host_ecdsa_521_key.pub -rw------- 1 root root 227 Jun 25 03:26 ssh_host_ecdsa_key -rw-r--r-- 1 root root 206 Jun 25 03:26 ssh_host_ecdsa_key.pub -rw------- 1 root root 444 Jun 25 03:26 ssh_host_ed25519_key -rw-r--r-- 1 root root 126 Jun 25 03:26 ssh_host_ed25519_key.pub -rw------- 1 root root 1675 Jun 25 03:26 ssh_host_rsa_key -rw-r--r-- 1 root root 426 Jun 25 03:26 ssh_host_rsa_key.pub [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# mkdir review_site/.ssh [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# vi review_site/.ssh/config [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# cat review_site/.ssh/config HOST 172.30.1.80 # 這個IP是gitlab服務器的IP地址 IdentityFile ~/.ssh/id_rsa PreferredAuthenticationns publickey [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# ll review_site/.ssh/config -rw-r--r-- 1 root root 85 Jun 25 07:09 review_site/.ssh/config [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# chmod 600 review_site/.ssh/config #修改權限~降低安全風險 [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# ll review_site/.ssh/config -rw------- 1 root root 85 Jun 25 07:09 review_site/.ssh/config [root@gerrit.yinzhengjie.org.cn ~]#
2>.配置gerrit replication功能(用於復制具體項目)
[root@gerrit.yinzhengjie.org.cn ~]# ll review_site/ total 12 drwxr-xr-x 2 root root 84 Jun 25 03:27 bin drwxr-xr-x 2 root root 4096 Jun 25 03:28 cache drwxr-xr-x 5 root root 69 Jun 25 03:31 data drwxr-xr-x 2 root root 78 Jun 25 03:28 db drwxr-xr-x 3 root root 4096 Jun 25 07:05 etc drwxr-xr-x 2 root root 6 Jun 25 03:25 git drwxr-xr-x 6 root root 114 Jun 25 03:27 index drwxr-xr-x 2 root root 6 Jun 25 03:20 lib drwxr-xr-x 2 root root 130 Jun 25 03:28 logs drwxr-xr-x 2 root root 288 Jun 25 03:27 plugins drwxr-xr-x 2 root root 6 Jun 25 03:20 static drwx------ 2 root root 4096 Jun 25 03:28 tmp [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]# cat ~/review_site/etc/replication.config #該文件需要手動創建 [remote "yinzhengjie_code"] #remote后面是項目名稱 projects = yinzhengjie_code #也是項目名稱 url = git@gitlab.yinzhengjie.org.cn:root/yinzhengjie_code.git #就是你gitlab服務器上面的項目刻隆地址,注意,這邊使用提ssh協議進行刻隆的, 所以不要選擇http方式了。 push = +refs/heads/*:refs/heads/* push = +refs/tags/*:refs/tags/* push = +refs/changes/*:refs/changes/* threads = 3 [root@gerrit.yinzhengjie.org.cn ~]# [root@gerrit.yinzhengjie.org.cn ~]#
3>.重啟Gerrit服務
[root@gerrit.yinzhengjie.org.cn ~]# cd review_site/bin/ [root@gerrit.yinzhengjie.org.cn ~/review_site/bin]# ll total 67132 -rwxr-xr-x 1 root root 438 Jun 25 03:27 gerrit.service -rwxr-xr-x 1 root root 16094 Jun 25 03:27 gerrit.sh -rwxr-xr-x 1 root root 109 Jun 25 03:27 gerrit.socket -rw-r--r-- 1 root root 68714982 Jun 25 03:26 gerrit.war [root@gerrit.yinzhengjie.org.cn ~/review_site/bin]# [root@gerrit.yinzhengjie.org.cn ~/review_site/bin]# ./gerrit.sh restart Stopping Gerrit Code Review: OK Starting Gerrit Code Review: OK [root@gerrit.yinzhengjie.org.cn ~/review_site/bin]#
七.驗證Gerrit和Gitlab的集成效果-使用客戶端直接提交代碼到Gitlab
1>.客戶端克隆Gerrit代碼后直接提交給master分支
[root@git.yinzhengjie.org.cn ~]# git clone "ssh://admin@gerrit.yinzhengjie.org.cn:29418/yinzhengjie_code" Cloning into 'yinzhengjie_code'... remote: Counting objects: 3, done remote: Finding sources: 100% (3/3) remote: Total 3 (delta 0), reused 3 (delta 0) Receiving objects: 100% (3/3), done. [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# ll total 0 drwxr-xr-x 3 root root 35 Jun 25 07:16 yinzhengjie_code [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# cd yinzhengjie_code/ [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# ll total 4 -rw-r--r-- 1 root root 41 Jun 25 07:16 README.md [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# echo "https://www.cnblogs.com/yinzhengjie/" >> blog.txt [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# ll total 8 -rw-r--r-- 1 root root 37 Jun 25 07:17 blog.txt -rw-r--r-- 1 root root 41 Jun 25 07:16 README.md [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git add blog.txt [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git config --global user.name "admin" [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git config --global user.email "admin@yinzhengjie.org.cn" [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git commit -m "add blog.txt" [master d064e5b] add blog.txt 1 file changed, 1 insertion(+) create mode 100644 blog.txt [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git push #我們直接提交到master,數據會直接提交的Gerrit中,而我們在Gerrit中編寫了同步的文件,因此,咱們沒有通過Gerrit審核就直接提交到gitlab中去啦!!!生產環境並不推薦這樣搞 warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 312 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: Processing changes: refs: 1, done To ssh://admin@gerrit.yinzhengjie.org.cn:29418/yinzhengjie_code 23b4540..d064e5b master -> master [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]#
2>.查看Gerrit日志
[root@gerrit.yinzhengjie.org.cn ~]# cat review_site/logs/replication_log [2019-06-25 07:20:16,220] [] scheduling replication yinzhengjie_code:refs/heads/master => git@gitlab.yinzhengjie.org.cn:root/yinzhengjie_code.git [2019-06-25 07:20:16,245] [] scheduled yinzhengjie_code:refs/heads/master => [edcdfd7f] push git@gitlab.yinzhengjie.org.cn:root/yinzhengjie_code.git to run after 15s [2019-06-25 07:20:31,248] [edcdfd7f] Replication to git@gitlab.yinzhengjie.org.cn:root/yinzhengjie_code.git started... [2019-06-25 07:20:31,285] [edcdfd7f] Push to git@gitlab.yinzhengjie.org.cn:root/yinzhengjie_code.git references: [RemoteRefUpdate[remoteName=refs/heads/master, NOT_ATTEMPTED, (null)...d064e5b53b48fe757ceea8714ff49de200ed2949, srcRef=refs/heads/master, forceUpdate, message=null]] [2019-06-25 07:20:32,073] [edcdfd7f] Replication to git@gitlab.yinzhengjie.org.cn:root/yinzhengjie_code.git completed in 824ms, 15004ms delay, 0 retries [root@gerrit.yinzhengjie.org.cn ~]#
3>.查看gitlab庫中的文件
4>.查看blog.txt文件內容,的確和我們寫的文件內容是一致的
八.驗證Gerrit和Gitlab的集成效果-使用客戶端提交代碼到Gerrit后,由Gerrit審核通過后在提交到Gitlab
1>.客戶端克隆Gerrit代碼后直接提交給master分支
[root@git.yinzhengjie.org.cn ~]# git clone "ssh://admin@gerrit.yinzhengjie.org.cn:29418/yinzhengjie_code" && scp -p -P 29418 admin@gerrit.yinzhengjie.org.cn:hooks/commit-msg "yinzhengjie_code/.git/hooks/" Cloning into 'yinzhengjie_code'... remote: Counting objects: 6, done remote: Finding sources: 100% (6/6) remote: Total 6 (delta 0), reused 6 (delta 0) Receiving objects: 100% (6/6), 532 bytes | 0 bytes/s, done. commit-msg 100% 1790 1.0MB/s 00:00 [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# cd yinzhengjie_code/ [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# ll total 8 -rw-r--r-- 1 root root 37 Jun 25 09:06 blog.txt -rw-r--r-- 1 root root 41 Jun 25 09:06 README.md [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# echo "尹正傑" > name.list [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git config --global user.name "admin" [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git config --global user.email "admin@yinzhengjie.org.cn" [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git add name.list [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git commit -m "add name.list" [master ce71335] add name.list 1 file changed, 1 insertion(+) create mode 100644 name.list [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git push origin HEAD:refs/for/master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 356 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: Processing changes: refs: 1, new: 1, done remote: remote: SUCCESS remote: remote: http://gerrit.yinzhengjie.org.cn/c/yinzhengjie_code/+/1 add name.list [NEW] remote: To ssh://gerrit.yinzhengjie.org.cn:29418/yinzhengjie_code * [new branch] HEAD -> refs/for/master [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]# git --version #需要注意的是,git版本最好使用git2.X版本喲~,否則在將代碼push到Gerrit的時候可能會報錯~在Gerrit服務端git版本好像git1.X版本也可以正常使用。 git version 2.12.2 [root@git.yinzhengjie.org.cn ~/yinzhengjie_code]#
2>.查看Gerrit的Web UI界面
3>.在Gerrit還沒有通過審批之前,我們克隆一下Gerrit代碼
[root@git.yinzhengjie.org.cn ~]# ll yinzhengjie_code/ #這是我們提交到Gerrit的代碼 total 12 -rw-r--r-- 1 root root 37 Jun 25 09:06 blog.txt -rw-r--r-- 1 root root 10 Jun 25 09:06 name.list -rw-r--r-- 1 root root 41 Jun 25 09:06 README.md [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# rm -rf yinzhengjie_code/ #我們將源文件刪除 [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# git clone "ssh://admin@gerrit.yinzhengjie.org.cn:29418/yinzhengjie_code" #從Gerrit的庫中clone一份出來,觀察里面的內容。 Cloning into 'yinzhengjie_code'... remote: Counting objects: 6, done remote: Finding sources: 100% (6/6) remote: Total 6 (delta 0), reused 6 (delta 0) Receiving objects: 100% (6/6), done. [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# ll yinzhengjie_code/ #很顯然,代碼庫中並沒有我們提交的代碼 total 8 -rw-r--r-- 1 root root 37 Jun 25 09:12 blog.txt -rw-r--r-- 1 root root 41 Jun 25 09:12 README.md [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]#
4>.在Gerrit還沒有通過審批之前,我們克隆一下Gitlab代碼
[root@git.yinzhengjie.org.cn ~]# ll total 0 drwxr-xr-x 3 root root 51 Jun 25 09:12 yinzhengjie_code [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# rm -rf yinzhengjie_code/ #刪除源文件 [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# git clone git@gitlab.yinzhengjie.org.cn:root/yinzhengjie_code.git #將gitlab的代碼克隆到本地。 Cloning into 'yinzhengjie_code'... The authenticity of host 'gitlab.yinzhengjie.org.cn (172.30.1.80)' can't be established. ECDSA key fingerprint is SHA256:dxYzHaEpkoSjSE0UDEtz14Y4dCn+GX3HJZ+P8AzsF54. ECDSA key fingerprint is MD5:f6:a9:3b:12:2c:44:2f:e3:d7:2f:0b:fb:b2:33:4f:99. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'gitlab.yinzhengjie.org.cn,172.30.1.80' (ECDSA) to the list of known hosts. remote: Counting objects: 6, done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0) Receiving objects: 100% (6/6), done. [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# ll yinzhengjie_code/ #很顯然,我們發現提交的代碼既不在Gerrit中也不再Gitlab中。 total 8 -rw-r--r-- 1 root root 37 Jun 25 09:16 blog.txt -rw-r--r-- 1 root root 41 Jun 25 09:16 README.md [root@git.yinzhengjie.org.cn ~]#
5>.評審Chenge
6>.點擊"Submit",會將代碼同步到Gerrit存儲庫,需要注意的是,Gerrit存儲庫我們配置和Gitla集成,因此2個同名的存儲庫數據應該時一致的喲~
7>點擊“CONTINUE”
8>.Change提交成功
9>.查看Change狀態
10>.在Gerrit通過審批之后,我們克隆一下Gerrit代碼
[root@git.yinzhengjie.org.cn ~]# ll total 0 drwxr-xr-x 3 root root 51 Jun 25 09:16 yinzhengjie_code [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# ll yinzhengjie_code/ #在審核之前,我們發現代碼並沒有被合並到主分支 total 8 -rw-r--r-- 1 root root 37 Jun 25 09:16 blog.txt -rw-r--r-- 1 root root 41 Jun 25 09:16 README.md [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# rm -rf yinzhengjie_code [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# git clone "ssh://admin@gerrit.yinzhengjie.org.cn:29418/yinzhengjie_code" #當我們審批通過后,再次clone代碼進行觀察 Cloning into 'yinzhengjie_code'... remote: Counting objects: 9, done remote: Finding sources: 100% (9/9) Receiving objects: 100% (9/9), done. remote: Total 9 (delta 0), reused 9 (delta 0) [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# ll yinzhengjie_code/ #很顯然,多了一個我們之前提交的文件"name.list",說明我們測試成功啦~ total 12 -rw-r--r-- 1 root root 37 Jun 25 09:43 blog.txt -rw-r--r-- 1 root root 10 Jun 25 09:43 name.list -rw-r--r-- 1 root root 41 Jun 25 09:43 README.md [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]#
11>.在Gerrit通過審批之后,我們克隆一下Gitlab代碼
[root@git.yinzhengjie.org.cn ~]# rm -rf yinzhengjie_code/ [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# git clone git@gitlab.yinzhengjie.org.cn:root/yinzhengjie_code.git Cloning into 'yinzhengjie_code'... remote: Counting objects: 9, done. remote: Compressing objects: 100% (5/5), done. remote: Total 9 (delta 1), reused 0 (delta 0) Receiving objects: 100% (9/9), done. Resolving deltas: 100% (1/1), done. [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]# ll yinzhengjie_code/ #不難發現,通過Gerrit審批后,Gitlab中的數據也被同步啦~這充分說明Gerrit和Gitlab集成成功啦~ total 12 -rw-r--r-- 1 root root 37 Jun 25 09:48 blog.txt -rw-r--r-- 1 root root 10 Jun 25 09:48 name.list -rw-r--r-- 1 root root 41 Jun 25 09:48 README.md [root@git.yinzhengjie.org.cn ~]# [root@git.yinzhengjie.org.cn ~]#