Java Project, Jenkins and GIT Intergration

 
Jenkins and GIT Integration

Java Project Creation with ythe help of Eclipse
1)Create  Java Project
2)Create "demo"  package
3)Create Java File "HelloWorld.java"

package demo;
public class ReverseNumber 
{

    public static void main(String[] args)
  {

        System.out.println("Hello World");
         }
}

4)Run Above code from Windows Command Prompt
a)Go to the project folder ex. cd C:\ABC\JenkinandGitJavaProgram\src\demo
b)Enter following command ex javac HelloWorld.java 
c)If we enter " java  HelloWorld.java" then it give us error due to java constraint 
  Enter "java demo.ReverseNumber"     Package should be required before ClassName

5)We will get output "Hello World"

Jenkins and Java Project Integration


Jenkins->Manage Jenkins->Global Tool Configuration
Need to installed following plugins 
HTML Publisher plugin
TestNG Result Plugin
Selenium HTML report

1)Install Jenkins 
2)Start Jenkins server 
a)First go to the jenkins folder ex "C:\Program Files (x86)\Jenkins>
b)Run Jenkins.war ex. "C:\Program Files (x86)\Jenkins>java -jar jenkins.war"
3)Login Jenkins Server by using username and password
4)Click on "New Item" to create new jenkin project
5)Then Enter Project Name ex ""HelloWorld" and select Free Style Project
6)Ok and Save
7)Go to the  Configure->Build-> select "Execute Windows Batch Envirnoment"
and enter folloing commands

cd C:\ABC\JenkinandGitJavaProgram\src\demo
javac HelloWorld.java
cd..
java demo.HelloWorld

8)Apply and Save
9)Click on  "Build Now" and see ouput on "console window"


Jenkins and Java Project and GIT Integration

1)Firstly Jenkins and Java Project Integration required, Install GIT Plugin into Jenkins via Manage Jenkins
2)Create a Github Account
3)Create a repository on GitHub ex "HelloWorldJava"
4)Then make the following changes into "Source Code Management" of Jenkins->HelloWorld
a)Select git instead of None to access code from a git repository
b)Then Enter git repository URL ex. "https://github.com/vpkhachane/HelloWorldJava.git"
c)Then In "Build Triggers"  Tick  "Poll SCM" Option and enter "* * * * *", this star execute script per minute
d)Then Apply and save it

Procedure to upload our project on GIT Repository
Login to Git and create a new repository and copy path for future reference "https://github.com/vpkhachane/HelloWorldJava.git"
Go to git bash command Prompt-> 
set project working directory ex. cd C://NewMobileAutomation//VaibhavTestingPractice//
git init                           //to initialize empty git repository on GitHub
git status    //to check the git update status
git add .  //add files 
git commit -m "Hello Java Program" 
git remote add origin https://github.com/vpkhachane/HelloWorldJava.git 
git push -u origin master   
To download Project
git clone https://github.com/vpkhachane/FirstGitPractice.git

to download changes made by others
git pull 

Jenkins execute the HelloWorld Project after every change 

For Jenkin Scheduler. We can follow the following steps
1)Start Jenkins
2)Open Project
3)Configure->Build Triggers->
4)Tick Build periodically option
5)Add Scheduler criteria ex. use "* * * * *"for every 1 minutes , "*/2 * * * *" for every two minutes,
 "*/15 * * * *" for every 15 minutes
Rerer link for timer