Gerrit x Jenkins


Created by Chu-Siang Lai / @chusiang

1. What is this?

1.1. What is the Gerrit?


  • 程式碼審查系統 (Code review system)。

https://android-review.googlesource.com/

1.2. What is the Jenkins?


  • 持續整合 (CI) 的 web-based 伺服器,並具有極高的擴充性及彈性。
  • 自動化測試。
Jenkins

https://builds.apache.org/

1.3. Gerrit + Jenkins = ?


資料來源:Terry Li

資料來源:Jocelyn Yang

資料來源:Workflow model: Using Gerrit and Jenkins together | Christian Bretterhofer

2. How to use?

2.1. Gerrit site

Create New Project

Gerrit → Project → Create New Project ...
Result

First Commit



$ git clone   ssh://jonny@192.168.33.25:29418/demo
              

$ echo 'Hell  o World' > readme.rst
              

$ git add re  adme.rst
              

$ git commit   -m "first commit."
              

git push ?
 
Gerrit 預設不允許直接對分支 (branch) push,需對 refs/for/<branch-name> 特殊引用 push 才可將提交納入審查系統。
除了使用 HEAD:refs/for/master 的 branch 以外,還需在 commit 裡補上 Change-Id

$ git push origin HEAD:refs/for/master
Counting objects: 4, done.
Writing objects: 100% (3/3), 252 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done    
remote: ERROR: missing Change-Id in commit message footer
remote: Suggestion for commit message:
remote: first commit.
remote: 
remote: Change-Id: I9001c46e4afae9f3e0021f7aba6608dccf05295e
remote: 
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jonny@192.168.33.25:hooks/commit-msg ${gitdir}/hooks/
remote: 
remote: 
To ssh://jonny@192.168.33.25:29418/demo
 ! [remote rejected] HEAD -> refs/for/master (missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://jonny@192.168.33.25:29418/demo'
            

$ git commit --amend 
...
Change-Id: I9001c46e4afae9f3e0021f7aba6608dccf05295e
            
push success.

$ git push origin HEAD:refs/for/master
Counting objects: 4, done.
Writing objects: 100% (3/3), 295 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: new: 1, refs: 1, done    
remote: 
remote: New Changes:
remote:   http://192.168.33.25/13
remote: 
To ssh://jonny@192.168.33.25:29418/demo
 * [new branch]      HEAD -> refs/for/master
            

※ 可搭配 git-review 簡化 git push,但需先行設定相關參數。

Code-review



http://192.168.33.25/#/c/13/

http://192.168.33.25/#/c/13/1,publish

push code 以後除了 Reviewer 人工審核外,也可搭配 jenkins 進行自動測試 (請搭配 流程圖 理解觀念)。


※ 由於在下還不會撰寫測試 code,故此 Demo 為手動 Verified。


http://192.168.33.25/#/c/13/

http://192.168.33.25/#/c/13/

2.2. Jenkins site


※ 由於 Jenkins 還未建置完,故只 Demo 部份功能。

Dashboard
S: 上次建置狀態, W: 建置成功率。
http://192.168.33.25:8080/
Building with javac.
http://192.168.33.25:8080/job/HelloWorld/
Message.
http://192.168.33.25:8080/job/HelloWorld/10/console
Building with not gerrit.
http://192.168.33.25:8080/job/sandbox/
Building with gerrit and not testing code.
http://192.168.33.25:8080/job/sandbox/
Reviewing with gerrit.

http://192.168.33.25/#/c/12/

2.3. Mail site

[Gerrit] Change in demo[master]: first commit.

jenkins@gerrit has posted comments on this change.

Change subject: first commit.
......................................................................


Patch Set 1: Verified+1

manual verified by jenkins user.

--
To view, visit http://192.168.33.25/13
To unsubscribe, visit http://192.168.33.25/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I9001c46e4afae9f3e0021f7aba6608dccf05295e
Gerrit-PatchSet: 1
Gerrit-Project: demo
Gerrit-Branch: master
Gerrit-Owner: Chu-Siang lai <chusiang.lai (dot) gmail.com>
Gerrit-Reviewer: Chu-Siang lai <chusiang.lai (dot) gmail.com>
Gerrit-Reviewer: jenkins@gerrit
Gerrit-HasComments: No
            
[Gerrit] Change in sandbox[master]: testing

jenkins@gerrit has posted comments on this change.

Change subject: testing
......................................................................


Patch Set 1:

Build Started http://192.168.33.25:8080/job/sandbox/18/
            

jenkins@gerrit has posted comments on this change.

Change subject: testing
......................................................................


Patch Set 1:

Build Failed

http://192.168.33.25:8080/job/sandbox/18/ : FAILURE
            
[Jenkins] 建置失敗: sandbox #18

查看 <http://192.168.33.25:8080/job/sandbox/18/>

------------------------------------------
Triggered by Gerrit: http://192.168.33.25/12
建置中 工作區 <http://192.168.33.25:8080/job/sandbox/ws/>
Fetching changes from the remote Git repository
Fetching upstream changes from ssh://jenkins@192.168.33.25:29418/sandbox.git
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
            

THE END