Book Image

Learning Gerrit Code Review

By : Luca Milanesio
Book Image

Learning Gerrit Code Review

By: Luca Milanesio

Overview of this book

<p>Developing software is now more than ever before a globally distributed activity: agile methodologies that worked well enough with co-located teams now need to be empowered with additional tools such as Gerrit code review to allow the developers to share, discuss, and cooperate in a more social way, even with GitHub.</p> <p>Learning Gerrit Code Review is a practical guide that provides you with step-by-step instructions for the installation, configuration, and use of Gerrit code review. Using this book speeds up your adoption of Gerrit through the use of a unique, consolidated set of recipes ready to be used for LDAP authentication and to integrate Gerrit with Jenkins and GitHub.</p> <p>Learning Gerrit Code Review looks at the workflow benefits of code review in an agile development team, breaks it down into simple steps, and puts it into action without any hassle. It will guide you through the installation steps of Gerrit by showing you the most typical setup and configuration schemes used in private networks.</p> <p>You will also learn how to effectively use Gerrit with GitHub in order to provide the ability to add more consistent code review functionality to the social collaboration tools provided by the GitHub platform. Using the two tools together, you will be able to reuse your existing accounts and integrate your GitHub community into the development lifecycle while keeping in touch with external contributors.</p>
Table of Contents (17 chapters)
Learning Gerrit Code Review
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Triggering a build from Gerrit


We need to define a Jenkins job to fetch the code from Gerrit and build it in the Continuous Integration environment. Additionally, we may want to disable all of the post validation phases except unit tests, in order to shorten the build execution time. Remember that this job will be triggered much more frequently than a typical Continuous Integration job.

Configuring the Gerrit trigger

We need to change the conditions for triggering a new build on the job from SCM polling (or other trigger policy) to Gerrit event. Additionally, we also need to specify the Gerrit conditions for the trigger action, available when clicking on the Advanced button in the Gerrit trigger specific configuration section.

The additional parameters needed are project name (specified as a plain complete text string) and branches (specified as the path regular expression **).

Configuring the Git plugin

Finally, we need to tell the Git plugin how to get the source code from the Gerrit trigger plugin. This inter-plugin communication happens through environment variables: Gerrit defines two variables ($GERRIT_REFSPEC and $GERRIT_PATCHSET_REVISION) populated respectively with the Gerrit ref-spec to fetch and the actual Change patch-set to be checked out.

We need then to edit the Git repository settings (by clicking on the Advanced button) in the following way:

  • Set $GERRIT_REFSPEC as the Git refspec to clone

  • Set $GERRIT_PATCHSET_REVISION as the Git branch to build

  • Set the choosing strategy to Gerrit trigger

We suggest that you enable two additional flags:

  • Wipe out workspace: Potentially each build could fetch a completely different branch of the code, without wiping out the workspace; we may risk relying on temporary files generated from previous builds.

  • Use shallow clone: Changes are typically well-defined unique snapshots of code; having the entire clone history on the local file system would not help and just increases the amount of disk space used.

These flags are not necessarily needed, but are strongly recommended for preventing future headaches when fetching and building multiple changes.