Git, Gerrit and
Jenkins
Code Review and Automated Build
Alex Blewitt
@alblue
SkillsMatter October 2011
Slide 2
Slide 2 text
Git
• Matthew has talked about Git extensively
• Ask @matthewmccull for more details :)
• Alternatively look for Git Tip of the Week
• #gtotw
• alblue.bandlem.com/search/label/gtotw
Slide 3
Slide 3 text
Gerrit
• Git-backed review system
• Used by Eclipse, Android
• Acts as a front-end to a central Git repo
• When review complete, auto-merged
Slide 4
Slide 4 text
Jenkins/Hudson
• Automated build platform
• Can be used with/without Gerrit/Git
• Has triggers to hook into events
• Hudson donated to Eclipse Foundation
• Jenkins donated to SPI
Slide 5
Slide 5 text
Problem
Why are we here again?
Slide 6
Slide 6 text
Team development
• Work as a team
• Merge to centralised repository
• Review all code changes
✓But without affecting others
Slide 7
Slide 7 text
Attempt I
• Review before commit
✓No cruft in repository
✓Doesn’t affect others
✴No guarantee reviewed == commited
Slide 8
Slide 8 text
Attempt II
• Review after commit
✓Guarantee reviewed == commited
✴Cruft in repository
✴May affect others
Slide 9
Slide 9 text
Attempt III
• Review after commit on unique branch
✓Guarantee reviewed == commited
✓No cruft in repository on main branch
✓Will not affect others
Slide 10
Slide 10 text
Pushing
• Pushing to Gerrit creates a new branch
• master:refs/for/master
• Review comments can be added to files
• Can compare before/after changes
• Change-Id allows patch sets per branch
Slide 11
Slide 11 text
Automated
checks
Does the change compile and test?
Slide 12
Slide 12 text
Checking it out
• Jenkins can be told when a change occurs
• Can automatically compile and test code
• Can generate test report
• Can mark success/failure in Gerrit
Slide 13
Slide 13 text
Jenkins Gerrit Trigger
• Can install the Gerrit Trigger Plugin
• Automatically installs Git plugin
• Set refspect to pull as $GERRIT_REFSPEC
• Build Trigger as Gerrit Event
• Project must match project(s)
• Project Path ** Branch Path **
Slide 14
Slide 14 text
Gerrit workflow
Slide 15
Slide 15 text
Demo
Putting it all together
Slide 16
Slide 16 text
Permissions
• Gerrit can act as a permissioned keeper
• Merges
• Push-to-branch directly (skip review)
• Clone/fetching
• Review/Submit
Slide 17
Slide 17 text
Commit Hooks
• Can be configured to auto add Change-Id
• Git
• scp -P 29418 gerrit:/hooks/commit-msg
• EGit
• git config gerrit.createchangeid true
Slide 18
Slide 18 text
Merging
• Can configure merge options per-project
• Fast Forward Only
• Merge If necessary
• Always Merge
• Cherry Pick
Slide 19
Slide 19 text
Review Notes
• Gerrit 2.2+ stores more info in Git repos
• Permissions are stored refs/meta/config
• Inherited from All-Projects.git
• Review data encoded in Git Notes
• refs/notes/review
• git log --show-notes=*
Slide 20
Slide 20 text
Future
• Currently (2.2) a SQL DB is still required
• SSH keys, user information
• Project metadata
• More info is moving to Git repositories
• Review notes
• Configuration
Slide 21
Slide 21 text
Git, Gerrit and
Jenkins
Code Review and Automated Build
Alex Blewitt
@alblue
SkillsMatter October 2011