Scheduling the Build in Jenkins!!!!


                      Scheduling the job in Jenkins!!!

Using Jenkins we can schedule jobs which we created

You can schedule buid for existing jobs which already created and while creating new project also we can specify the same.

 Lets schedule the job. Refer the below screenshot


Step 1-Click on configure then select the check box build periodically 











Step 2- Specify the time here we need to careful about the syntax 

Jenkins will accept 5 parameter lest discuss one by one * * * * *

Here first parameter- specify minute and range will vary from 0-59

 Here second parameter- specify hours and range will vary from 0-24

Here third parameter- specify day and range will vary from 0-7 here 0 and 7 will be sunday

Here fourth parameter- specify month and range will vary from 1-12

Here fifth parameter- specify year so here you can specify *

Example 1- if you specify 00 22 * * * it means your build will run daily @ 10 PM

Example 2- if you specify 50 * * * * it means your build will run daily 50 min after every hour

Example 3- if you specify 00 22 1 * * it means your build will run every monday @ 10 PM


Running Testng Programs from Jenkins!!!

                
Step 1- Lets create a windows batch which is required to invoke from Jenkins.

 To create batch file we need to set classpath of testng so that we can execute testng.xml files.

Our project structure should look like















Open command and set the classpath and execute the program from command line

 While setting classpath we will set the path of bin folder and libs folder (inside libs we have all libraries).

Setting the classpath as below:

C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject> set classpath=C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\bin;C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\lib\testng-6.8.5.jar;C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\lib\jcommander-1.29.jar 








C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject>java org.testng.TestNG testng.xml














Open notepad and type the below commands and save as .bat file –Copy the run.bat in the project directory. Contents of the run.bat as follows:

set classpath=C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\bin;C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\lib\testng-6.8.5.jar;C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\lib\jcommander-1.29.jar

java org.testng.TestNG testng.xml




















Step 2- Now create a job in Jenkins which will execute our Testcases.

a. Open Jenkins on browser (type http://localhost:8080) 

Click on new item 












b. Specify the name of Job-Name, select Build a free-style software project and Click on OK button .
















c. Navigate to Advanced Project Options > Check the use custom workspace > in directory  specify the project home directory.












d.  Now the final and most important part specify the Add Build step >Click on Execute Windows batch command.















 e. In the command section specify the batch file which we created and click on on Apply and save













Step 3- Now finally run the Build > Click on Build now.
















Step 4- Check Build history and Console output and verify the output.


































How to schedule buid in Jenkins

Downloading Jenkins

Download Jenkins

Step 1- Navigate to Below URL   http://jenkins-ci.org













Step 2-Download Jenkins.war and save into desktop

Open Command prompt and navigate till project home directory and Start Jenkins server

This is how to run jar files from the command line.

















Step 3- Once Jenkins server is up. You will get above success message. 

Open any browser and type the url http://localhost:8080

Note- By default Jenkins will start on 8080 port number

 Now Jenkins in up and running so now we have to configure Jenkins so that we can execute our test case via Jenkins

Step 4- Once Jenkins is running so we are done but before moving to create build we need to configure Jenkins Click on --> Manage Jenkins.



Click on Configure System.










Navigate to JDK section and Click on Add JDK button.












Uncheck Install automatically check box so Jenkins will only take java which we have mention above. 











Give the name as JAVA_HOME and Specify the JDK path.










Running Testng Programs from Jenkins!!!