Integrate Jenkins with GIT SCM

TO configure Git in Jenkins, first log in to your Jenkins server and in your Dashboard left side there is an option "Manage Jenkins", click on it

Now click on "Manage Plugins" on the next screen.

In the next screen click on "Available" tab.

You get a list of Plugins, in this list there so many Plugin, in 'Filter' box we put 'Git Plugin'.

Now we select the 'Git Plugin' check-box  and press the "Install without restart"

you get the following screen

Once all installations are complete, restart the Jenkins server by selecting ""  at the bottom of the page.

Now login again to Jenkins dashboard.

After Jenkins is restarted, Git will be available as an option whilst configuring jobs. To verify, click on New Item in the menu options for Jenkins. Then enter a name for a job, in the following case, the name entered is ‘JenkisDemo’. Select ‘Freestyle project’ as the item type. Click the Ok button.

In the next screen when you click on "Source Code Management" tab you get GIT as an option

Jenkins continous Integration tool

What is Continuous Integration ?

Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly. This article is a quick overview of Continuous Integration summarizing the technique and its current usage. 

The main aim of CI is to prevent integration problems, referred to as "integration hell"

A continuous integration server acts as a monitor to the repository. Every time a commit against the repository finishes the server automatically checks out the sources onto the integration machine, initiates a build, and notifies the committer of the result of the build. The committer isn't done until she gets the notification - usually an email.

What is Jenkins ? 

Jenkins is a popular open source tool to perform continuous integration and build automation. The basic functionality of Jenkins is to execute a predefined list of steps, e.g. to compile Java source code and build a JAR from the resulting classes. The trigger for this execution can be time or event based. For example, every 20 minutes or after a new commit in a Git repository.

Environment Set up for Jenkins ?

Jenkins can be installed through native system packages, Docker, or even run standalone by any machine with the Java Runtime Environment installed.

1. In this tutorial we use standalone distribution. TO download the Jenkis click on the given Jenkins link.

2. Go to the directory where you download the Jenkins war file and run the following command-

$ java -jar jenkins.war

After the command is run, various tasks will run, one of which is the extraction of the war file which is done by an embedded webserver called winstone.

Running from: /home/expert/Downloads/jenkins.war
webroot: $user.home/.jenkins
Jul 24, 2017 10:18:48 PM Main deleteWinstoneTempContents

WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war
Jul 24, 2017 10:18:48 PM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Logging initialized @454ms
Jul 24, 2017 10:18:48 PM winstone.Logger logInternal
INFO: Beginning extraction from war file

3. Go to browser and type http://localhost:8080/
an authentication window is opened and it will ask you to enter the user and password.

type user as admin and password for this you get on server machine in the location ${user.home}/.jenkins/secrets/initialAdminPassword

after succesfull authentication you will get the Jenkins dashboard


Convention for Versioning of your project build

As we know that when we use any software tool or dependency or OS, they all come up with vesrion number like 2.1.1.

As a Software Engineer, developer and programmer we must understood what these version numbers.

So In this tutorial I will explain you about these version number.

The common convention for version numbers is

major. is incremented when something major is changed in your project.  For example, suppose you have removed a functionality, or changes the  signature of a function. so if client uses new version of project, changes can break the project of Clients using your library, so your client  need to take care when using a library with a different major version.

minor is incremented when something new added to your project but all the old functionality is same, For example, a method is added. In this case your client doe not worry about using the new version.Clients do not need to worry about about using the new version, as all the functions they are used to seeing will still be there and act the same.

build is incremented when the implementation of a function changes, but no signatures are added or removed. For example, you found a bug and fixed it. Clients should probably update to the new version, but if it doesn't work because they depended on the broken behavior, they can easily downgrade.

What Browser do when you type a address in your Browser Addres bar

As a end user, we do not have to know about what the browser do,  when we type an address in Browser.

But as a Programmer or Software Engineer some time we involve in web programming. As we know that web programming include HTTP, HTML, CSS, web server and so on.

Mostly novice programmer have an abstract idea about, what is happening behind the scene. In this tutorial I will try to take all of you into a deeper picture of behind the scene.

Suppose we are going to read a tutorial on techie-knowledge

1. We type the interested address(URL) in the Browser address bar.


2.  As we know the address which we have type is known as domain-name. Internet works on IP address.
     so it is clear that domain name converted to IP  address.

    a. So after typing the URL in browser, browser first extract the domain name from the URL.
    b. then browser queries to your pre-configure DNS server to find the IP address of the domain.Some               time it may be happen that DNS server have not the IP for domain, In this case DNS server will                    forward the query along to  DNS server it is configured to defer to.

     c. After getting IP address browser sends a HTTP request  original site

       d. After getting the response browser render the page to browser.

MAVEN archetype

MAVEN archetype is predefined template for specific project type like web project, spring project,  provided by Maven. In Maven a template is called an archetype.

As we know that when we create a project in eclipse it ask us to select the type of project like simple java project, dynamic web project ... when we select the type of project a structure of the project is created by eclipse.

similarly maven provides different archetype to create project.

Using an Archetype :

To create a new project based on an Archetype, you need to call mvn archetype:generate goal, like the following:

$ mvn archetype:generate
when you run this command maven download the diffrent archetype provided by maven, and ask you to select the archetype for your project.

sample output of the command

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------ [INFO]
[INFO] maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] [INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype:
1: remote -> am.ik.archetype:maven-reactjs-blank-archetype (Blank Project for React.js)
2: remote -> am.ik.archetype:msgpack-rpc-jersey-blank-archetype (Blank Project for Spring Boot + Jersey)
3: remote -> am.ik.archetype:mvc-1.0-blank-archetype (MVC 1.0 Blank Project)
4: remote -> am.ik.archetype:spring-boot-blank-archetype (Blank Project for Spring Boot)
5: remote -> am.ik.archetype:spring-boot-docker-blank-archetype (Docker Blank Project for Spring Boot)
6: remote -> am.ik.archetype:spring-boot-gae-blank-archetype (GAE Blank Project for Spring Boot)
7: remote -> am.ik.archetype:spring-boot-jersey-blank-archetype (Blank Project for Spring Boot + Jersey)
8: remote -> at.chrl.archetypes:chrl-spring-sample (Archetype for Spring Vaadin Webapps)
9: remote -> (an archetype web 3.0 + struts2 (bootstrap + jquery) + JPA 2.1 with struts2 login system)
10: remote -> (An Archetype with JPA 2.1; Struts2 core; Jquery struts plugin; Struts BootStrap plugin; json Struts plugin; Login System using Session and Interceptor)
11: remote -> (Anteros Archetype for Java Web projects.)
12: remote -> (Modelos com Anotações Gson)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 1007:
Press Enter to choose to default option or chosse the number of archetype. Enter project detail as asked.Press Enter if default value is provided. You can override them by entering your own value.
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6:
Define value for property 'groupId':
Define value for property 'artifactId': mvntest
Define value for property 'version' 1.0-SNAPSHOT: :
Define value for property 'package' :

Maven will ask for project detail confirmation. Press enter or press Y
Confirm properties configuration:
artifactId: mvntest
version: 1.0-SNAPSHOT
package: com.esc.mvntest
Y: :
Now Maven will start creating project structure and will display the following:
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1
[INFO] ---------------------------------------------------------------------------- [INFO] Parameter: basedir, Value: /home/expert
[INFO] Parameter: package, Value: com.esc.mvntest
[INFO] Parameter: groupId, Value:
[INFO] Parameter: artifactId, Value: mvntest
[INFO] Parameter: packageName, Value: [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] project created from Old (1.x) Archetype in dir: /home/expert/mvntest
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 06:26 min
[INFO] Finished at: 2017-07-19T18:10:36+05:30
[INFO] Final Memory: 18M/199M
[INFO] ------------------------------------------------------------------------
You'll see a java application project created named mvntest which was given as artifactId at the time of project creation. Maven will create a standard directory layout for the project as shown below:
├── pom.xml
└── src
        ├── main
        │        └── java
        │              └── com
        │                       └── xyz
        │                               └── mvntest
        │                                              └──
        └── test
               └── java
                      └── com
                             └── xyz
                                     └── mvntest
Maven generates a POM.xml file for the project as listed below:
<project xmlns="" xmlns:xsi=""




</project> file which was created by maven 

package com.esc.mvntest;

 * Hello world!
public class App
    public static void main( String[] args )
        System.out.println( "Hello World!" );
Compiling code

To compile the code we use the following command
$ mvn compile
The sample output of the above commmand
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------
[INFO] Building mvntest 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mvntest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/expert/mvntest/src/main/resources
[INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ mvntest ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.150 s
[INFO] Finished at: 2017-07-22T11:04:23+05:30
[INFO] Final Memory: 7M/121M
[INFO] ------------------------ ------------------------------------------------

Packaging the code

As we know that this project is just a simple java program so we can create the jar file of this project. To create the jar file of the project we use the following command

The default naming convention of Maven artifacts is: {artifact-name}-{artifact-version}

$ mvn package

Sample output of the following command

[INFO] Scanning for projects...
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] Building mvntest 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mvntest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/expert/mvntest/src/main/resources
[INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ mvntest ---
[INFO] Nothing to compile - all classes are up to date
[INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mvntest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/expert/mvntest/src/test/resources
[INFO] [INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ mvntest ---
[INFO] Nothing to compile - all classes are up to date
[INFO] [INFO] --- maven-surefire-plugin:2.17:test (default-test) @ mvntest ---
[INFO] Surefire report directory: /home/expert/mvntest/target/surefire-reports
Running com.esc.mvntest.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec - in com.esc.mvntest.AppTest
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mvntest ---
[INFO] Building jar: /home/expert/mvntest/target/mvntest-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.885 s
[INFO] Finished at: 2017-07-22T11:28:38+05:30
[INFO] Final Memory: 16M/158M
[INFO] ------------------------------------------------------------------------


MAVEN build phase

Maven build life cycle 

The build life cycle is divided into build phases, and the build phases are divided into build goals.
Every build follows a specified life cycle. Maven comes with a default life cycle that includes the most common build phases like compiling, testing and packaging. 

Build Life Cycles
Maven has 3 built-in build life cycles. These are:
  1. default (build) : Used to create the application
  2. clean : Cleans up artifacts that are created by prior builds
  3. site : For the project generates site documentation
Build phase : Each build life cycle is divided into a sequence of build phases, and the build phases are again subdivided into goals. Thus, the total build process is a sequence of build life cycle(s), build phases and goals.

The following lists gives an overview of the important Maven life cycle phases.
  • validate - checks if the project is correct and all information is available
  • compile - compiles source code in binary artifacts
  • test - executes the tests
  • package - takes the compiled code and package it, for example into a JAR file.
  • integration-test - takes the packaged result and executes additional tests, which require the packaging
  • verify - performs checks if the package is valid
  • install - install the result of the package phase into the local Maven repository
  • deploy - deploys the package to a target, i.e. remote repository 
we can execute one of these build phases by passing its name to the mvn command. Here is an example:

$ mvn compile

This example executes the compile build phase, and thus also all build phases before it in Maven's predefined build phase sequence.

Note : Calling a build phase will execute not only that build phase, but also every build phase prior to the called build phase. 

Given the build phases above, when the default lifecycle is used, Maven will
  1. validate the project
  2. compile the sources
  3. run those against the tests
  4. package the binaries (e.g. jar)
  5. run integration tests against that package
  6. verify the package
  7. install the verifed package to the local repository
  8. deploy the installed package in a specified environment
  To do all those, you only need to call the last build phase to be executed, in this case, deploy:
mvn deploy

The following lists all build phases of the default, clean and site lifecycles, which are executed in the order given up to the point of the one specified.

Clean Lifecycle

pre-clean execute processes needed prior to the actual project cleaning
clean remove all files generated by the previous build
post-clean execute processes needed to finalize the project cleaning

Default Lifecycle

validate validate the project is correct and all necessary information is available.
initialize initialize build state, e.g. set properties or create directories.
generate-sources generate any source code for inclusion in compilation.
process-sources process the source code, for example to filter any values.
generate-resources generate resources for inclusion in the package.
process-resources copy and process the resources into the destination directory, ready for packaging.
compile compile the source code of the project.
process-classes post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.
generate-test-sources generate any test source code for inclusion in compilation.
process-test-sources process the test source code, for example to filter any values.
generate-test-resources create resources for testing.
process-test-resources copy and process the resources into the test destination directory.
test-compile compile the test source code into the test destination directory
process-test-classes post-process the generated files from test compilation, for example to do bytecode enhancement on Java classes. For Maven 2.0.5 and above.
test run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
prepare-package perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above)
package take the compiled code and package it in its distributable format, such as a JAR.
pre-integration-test perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
integration-test process and deploy the package if necessary into an environment where integration tests can be run.
post-integration-test perform actions required after integration tests have been executed. This may including cleaning up the environment.
verify run any checks to verify the package is valid and meets quality criteria.
install install the package into the local repository, for use as a dependency in other projects locally.
deploy done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

Site Lifecycle

pre-site execute processes needed prior to the actual project site generation
site generate the project's site documentation
post-site execute processes needed to finalize the site generation, and to prepare for site deployment
site-deploy deploy the generated site documentation to the specified web server


Maven Repository

Maven repository is a place where we find or put the jar files, plug-ins. Maven use these repository to locate the dependencies of the project which we define in pom.xml file.

Maven uses three types of repository -

  • Local
  • Centeral
  • Remote
the order of serching the dependency by maven is given below -

local -- > centeral --> remote

first it search on local repository and then central repository  and then remote repositroy. if the maven is not find dependencies in these repository it throws error

Local Repository :  When you install and run maven first time, it will create a .m2 directory on your home directory, which contains a another directory name repository like-


This the default location for the jar which maven check. If the particular jar is not in local repository then it will be downloaded from the remote repository which is set by maven when we installed the maven.

Central Repository : Maven central repository is repository provided by Maven community. It contains a large number of commonly used libraries.

When Maven does not find any dependency in local repository, it starts searching in central repository using following URL:

Remote Repository :  which is developer's own custom repository containing required libraries or other project jars.

Maven POM

Pom File: 

POM is stands for "Project Object Model" is an xml file which contains information about the project which you want to build and configuration details used by MAVEN to build the project.

For example it define the directory structure for your source file and your class file. and also define the location where dependencies related to your project is stored.

POM also contains the goals and plugins. While executing a task or goal, Maven looks for the pom.xml in the current directory.

Some of the configuration that can be specified in the POM are following:
  • project dependencies
  • plugins
  • goals
  • build profiles
  • project version
  • developers
  • mailing list

Sample Pom

There should be a single POM file for each project.

 * project – root element of every pom file.

* modelVersion – The modelVersion element sets what version of the POM        model you are using

* groupId – The groupId element is a unique ID for an organization, or a project

* artifactId – The artifactId element contains the name of the project you are building

* version – The version element contains the version number of the project.

The above groupId, artifactId and version elements would result in a JAR file being built and put into the local Maven repository.

Super POM :

All POMs inherit from a parent (despite explicitly defined or not). This base POM is known as the Super POM, and contains values inherited by default.  

All Maven project POMs extend the Super POM, which defines a set of defaults shared by all projects.

Effective POM :

Maven use the effective pom (super pom + pom.xml ) to execute relevant goal.



Defining Dependency on POM file for your project : sample pom for defining dependencies


Maven Installation In Ubuntu

How to Install Maven ?


JAVA 1.5 or above. 

Follow the given link to see how to install java and set environment for java in ubuntu.

Installation of Maven on ubuntu can be pretty straightforward 

Type the below commands on terminal.

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install maven

It takes few minutes to download, patient.


Type “mvn -version” to verify the installation.
$ mvn -version
Output should something like this-

Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /opt/jdk1.8.0_131/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-83-generic", arch: "amd64", family: "unix"

Where the Maven installed?

The apt-get installation will install all the required files in the following folder structure-

  1. /usr/bin/mvn
  2. /usr/share/maven/
  3. /etc/maven   (this is the maven configuration location)

Using maven behind proxy

To use maven behind the proxy we have to define the proxy setting in setting.xml  file inside the proxy element.
The setting file is found in /etc/maven/setting.xml
Add the following line under proxy element

What is Maven ?

What is Maven ?

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of Information.

apche maven

I used the maven to compile and package my storm topology to run on storm cluster both in production mode and local mode.

Maven provides developers ways to manage the following:
  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Releases
  • Distribution
  • mailing list

Convention over Configuration

Maven uses Convention over Configuration which means developers are not required to create build process themselves. Developers do not have to mention each and every configuration details.

Developers don't need to say every last design detail. Expert gives sensible default conduct to ventures. At the point when a Maven extend is made, Maven makes default extend structure. Developer is just required to put records in like manner and he/she require not to characterize any design in "pom.xml".

Dependency management:

It is a concept of maintain jars of a project, maintain child jars and parent jars (dependency-chaining)

maintain proper version of all jars (dependency-version)

Library : It is collection of Jars.

Maven is a Tool (software) used to handle dependency-management as automated ie jars,
chain jars with version management should be taken care by maven tool. It is developed by Apache.

Every jar (depedency) contains 3 details mainly. Those are groupId (jar provider/company
name) artifactId (jar name) & version (jar version). Maven maintains all jars as Library also called as Maven Library.

Default structure provided by Maven for a project

 Feature Summary

The following are the key features of Maven in a nutshell:

1) Simple project setup that follows best practices - get a new project or module started in seconds

2)  Consistent usage across all projects - means no ramp up time for new developers coming onto a project

3) Superior dependency management including automatic updating, dependency closures (also known as transitive dependencies)

4)  Able to easily work with multiple projects at the same time

5)  Model based builds: Maven is able to build any number of projects into predefined output types such as a JAR, WAR, or distribution based on metadata about the project, without the need to do any scripting in most cases.

6) Coherent site of project information: Using the same metadata as for the build process, Maven is able to generate a web site or PDF including any documentation you care to add, and adds to that standard reports about the state of development of the project. Examples of this information can be seen at the bottom of the left-hand navigation of this site under the "Project Information" and "Project Reports" submenus.

7) Release management and distribution publication: Without much additional configuration, Maven will integrate with your source control system (such as Subversion or Git) and manage the release of a project based on a certain tag. It can also publish this to a distribution location for use by other projects. Maven is able to publish individual outputs such as a JAR, an archive including other dependencies and documentation, or as a source distribution.

8) Dependency management: Maven encourages the use of a central repository of JARs and other dependencies. Maven comes with a mechanism that your project's clients can use to download any JARs required for building your project from a central JAR repository much like Perl's CPAN. This allows users of Maven to reuse JARs across projects and encourages communication between projects to ensure that backward compatibility issues are dealt with. 
 Maven Installation In Ubuntu

References :