Skip to main content

CONTINOUS INTEGRATION USING JENKINS, GIT, AND MAVEN

Jenkins is an open source automation server intended to automate repetitive technical tasks involved in the continuous integration and delivery of software.This tutorial shows you how we can set up Jenkins, Git, and Maven to work together and provide a smooth continuous integration system.

INSTALLING JENKINS
First, we'll add the repository key to the system
#wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
Next, we'll append the Debian package repository address to the server's sources.list:
#echo deb https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list
Now update
#apt-get update
Now install jenkins
#apt-get install jenkins
Then we will start and enable Jenkins service
#systemctl start jenkins
#systemctl enable Jenkins

Now open jenkins from browser http://your_ip:8080. It will ask us to login by using password under /var/lib/jenkins/secrets/initialAdminPassword.Login by using that password.Select install suggested plugins.This will install suggested plugins.Now give new admin user name password mail id and other details and click save.




Now the next step is to install plugins.
Go to Manage Jenkins > Manage plugins
Select the plugins we want.Here we want github and maven integration plugins.Select those plugins.Click on install without restart.








Now restart jenkins service
#service jenkins restart
Now our plugins are installed.Now we can configure our job.
Go to Jenkins Dashboard > New Item > type job name > Free style project


There will be different sections.Under General give project name,description.
Usually Jenkins will create log files on each builds.It uses memory and can result in running out of space.So under Discard old builds we will specify number of days we want to keep the build or number of builds we want to keep.Usually we set the days to our release cycle.
Under Project is parameterized we can set parameters that we want to pass.

Then Under Source Code management.Select the SCM we uses.Since we are using Git select git.Give the url of repository.There will be a branch specifier.Since we are using master branch.Keep as it is.

Under Build Triggers we will select how to trigger the build.
Build periodically will trigger build at periodic intravels based on intravel we gave.
Build after other projects are built: Here we can give project name after which our build is to be executed.
Poll SCM will trigger a build only when source repository is changed.we need to only set the intravel it will check repository.Here we will set Poll SCM as * * * * * so that it will check in every minute.

Under Build section select Invoke top-level Maven targets.Now give "clean Pacakage" over there.This will execute mvn clean package command.




Click on Save and Apply.

INSTALLING MAVEN
Before installing maven we will install java
#add-apt-repository ppa:webupd8team/java
#apt-get update -y
#apt-get install oracle-java8-installer

Now we will install maven.By default maven 3.3.9 is available on ubuntu 16.
#apt-get install maven
To check maven version.
#mvn –version
Now go to dashboard.Click on build now.
If it comes red build is failure.If it comes blue build is success.