Setting up continuous integration on linux
Overview
Continuous integration (CI) is a
software engineering practice in which isolated changes are immediately
tested and reported on when they are added to a larger code base. The
goal of CI is to provide rapid feedback so that if a defect is
introduced into the code base, it can be identified and corrected as
soon as possible.
The Big picture
GIT
It's a distributed version control system. Installing it is a cake walk.
Installation
Installing for linux
Configuration
Run git --version to be sure in the cmd or terminal depending on your OS.
Gerrit
It's your code review system that intercepts your code push to the repository.
Installation
Download it here...
Configuration
Gerrit requires a database in which all the reviews history will be stored for later retrieval.Let's setup mysql for the same (however you can use postgres as well).
Create a gerrit user on your system
Create a gerrit specific user
CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'your-password'; CREATE DATABASE reviewdb; ALTER DATABASE reviewdb charset=latin1; GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost'; FLUSH PRIVILEGES;
Initialize the schema
java -jar CreateSchema
Add indexes
A script should be run to create the query indexes, so Gerrit can avoid table scans when looking up information. Run the index script through your database's query tool.
java -jar gerrit.war --cat sql/index_generic.sql | mysql reviewdb -u gerrit2 -p java -jar gerrit.war --cat sql/mysql_nextval.sql | mysql reviewdb -u gerrit2 -p
Configure site path
This directory holds server-specific configuration files and assets used to customize the deployment. Gerrit needs read access (but not write access) to the directory. The path is stored in system_config.site_path, so you will need to update the database with this value.
mkdir /home/gerrit2/cfg cd /home/gerrit2/cfg
UPDATE system_config SET site_path='/home/gerrit2/cfg'
Starting gerrit
java -jar gerrit.war init --batch -d ~/gerrit_testsite
Observer the result
http://localhost:8080/login/#/
Gerrit trusts user with keys
You need to add your public ssh keys to the gerrit for it to authenticate you.
ssh-keygen -t rsa
Press enter and nothing else till you see a key on your terminal.
Verify your initialization
ssh user@localhost -p 29418
Project creation
ssh -p 29418 user@localhost gerrit create-project --empty-commit --name demo-project
For existing projects see thisYour first change
Usually when you push to a remote git, you push to the reference'/refs/heads/branch'
, but when working with Gerrit you have to push to a virtual branch representing "code review before submission to branch". This virtual name space is known as'/refs/for/branch'
git clone ssh://user@host:29418/demo-project
date > testfile.txt
git add testfile.txt
git commit -m "My pretty test commit"
git push origin HEAD:refs/for/master
sudo adduser gerrit2
sudo su gerrit2
Jenkins
Every time you push a patch you need the tests to be run on it and report should be generated.Well Jenkins does helps you in that.
Installation
Download it here here
Configuration
-
Start
java -jar /path/to/jenkins.war --httpPort=port -
Installing a plugin
1. Start
java -jar /path/to/jenkins.war --httpPort=port2. Visit your local jenkins
http://localhost:port
3.Installing Gerrit Trigger plugin
This plugin triggers a build when a new patch is pushed into the gerrit (Code Review System).
Depending on your needs you would have to add new plugins.
Figure 1 depicts the process.
Figure 1 -
Configuring the plugin
Go to Manage plugins -> Gerrit Trigger (After installing it , it should be there)
1. Open the plugin
http://localhost:1234/gerrit-trigger/
Configure your project server.
Figure 2 5.Creating a job for your project
-
Verifying Jenkins setup
http://localhost:port/gerrit_manual_trigger/Select your project and press search to see if your patchets appear or not.
With you should be go to go. -
Summary
We clone a git project and we do some changes and push it to gerrit.Inside Jenkins we installed a plugin named GerritTrigger. It has been configured to run a job every time a patch is pushed.
Let me know if you face any issues in the comment section.
Comments
Post a Comment