Join us on :

Jenkins

Jenkins is an open source automation server written in Java. Jenkins helps to automate the non-human part of software development process, with continuous integration.

It works based on plugins i.e. have to install respective plugins in order to communicate. For example Maven, Git plugins have to install with configuration.

Instead of pulling the entire code for building and testing. You can just use Jenkins to automatically fetch the code from repository, build and test it in the test environment and can send an email notification about the results so it will be easier to find the bug in that version of commit, instead of going through the whole code to find the bug.

Advantages of Jenkins

  • It is open source and it is user-friendly, easy to install and does not require additional installations or components.
  • Easily Configurable. Jenkins can be easily modified and extended. It deploys code instantly, generates test reports. Jenkins can be configured according to the requirements for continuous integrations and continuous delivery.
  • Platform Independent. Jenkins is available for all platforms and different operating systems, whether OS X, Windows or Linux.
  • Rich Plugin ecosystem. The extensive pool of plugins makes Jenkins flexible and allows building, deploying and automating across various platforms.
  • Easy support. Because it is open source and widely used, there is no shortage of support from large online communities of agile teams.
  • Developers write the tests to detect the errors of their code as soon as possible. So the developers don’t waste time on large-scale error-ridden integrations.
  • Issues are detected and resolved almost right away which keeps the software in a state where it can be released at any time safely.
  • Most of the integration work is automated. Hence fewer integration issues. This saves both time and money over the lifespan of a projec

Install Jenkins


1. Navigate to : https://jenkins.io/download/

2. Download the Generic war files, choose the war file from the stable relaese
3. Go to the folder in terminal/CMD where you have stored the jenkins.war file and execute below command.


							java -jar jenkins.war			
							


4. You would be able to success screen once we execute the command.

5. Navigate to the url in your browser http://localhost:8080, sometimes a it may take upto 3 minutes to open the page, so have patience if you get no page/ error page.

6. Please navigate to the highlighted path in your browser, and copy the password. 7. Install / select plugins based on your need, you can install plugins after installation of jenkins as well. 8. You may need to wait for 10-15 mins for completion of installytion of plugins. 9.Fill the use details and contunie 10. Click on start jenkins button 11. If you reached below page then you installtion is successsful.

Single Inheritance in Selenium and java

Run Selenium with Batch file

Create a selenium sample test using TestNg as unit testing framework, and create testng.xml. Below is the same test file we have created :


							public class TestJenkins {
								@Test
								public void openGoogle() {
									System.out.println("Test  Started");
									System.setProperty("webdriver.chrome.driver", "D:\\PATH\\chromedriver.exe");
									System.out.println("open browser");
									WebDriver driver = new ChromeDriver();
									driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
									System.out.println("open google");
									driver.get("https://google.com");
									driver.quit();
									System.out.println("Test Ended");
								}
							}			
							


Once you crate the testng.xml file, place the below jars under "jars" folder:

  • testng
  • Jcommander
  • Selenium standalone server


Now execute the below command in the cmd/terminal to open run the test case, you must be inside the project folder with cmd i.e where you have the .classpath file.


							java -cp Class_Files_Path; Jars_Path org.testng.TestNG testng.xml
							java -cp bin;jars/* org.testng.TestNG testng.xml			
							




If you command line execution is successful, then add the same line into the notepad and save the file as run.bat

Now try to run the bat file by double clicking, it should perform same operations like cmd execution.

Set Jenkins Job

Open jenkins and select 'New Item'

Enter the Job name, and Select Free Style project and click ok button.

Select Custom workspace under General section and provide the project folder details.

Under Build Section, choose Execute window batch command and provide our batch file name.

Click Save button, jenkins now will open the home page.

Click the Build Now link to run our project in Jenkins

Once the Jobs starts Heart beat starts, orange sphere is the heart beat and the Green arrow is Build Name.

Now click the build number to see the details, and select Console Output option

If you compare above output, it will exactly match with the output occured when we ran with cmd.

Lets learn how to add some colorful results to jenkins rather than console log summary.

Jenkins Plugins

Jenkins provides all the standard operations and if we want to have more options like reposting, something like theat then we should install the plugind for the jenkins.



Go to Available tab and search for TestNG; you may get result for TestNG results, select it and install

If your installtion is successful then you may see the success information like below

Generate Report in Jenkins

Once the TestNG plugin is installed the Choose to confugure the Build.

Go to Post Buils option and select Publish TestNG results, it may populate default values of it. In advanced section you can make the build as unstable, if a test fails.

Save the changes made so far.

Run the project again using Build Now Link, refresh the Page

Click the TestNG Results and select the Bulild Number, now it will navigate to result page.

Master Slave in Jenkins

SO for you are working in Master, now lets try to setup the lsave machine for this master so that we can run multiple jobs at same time.

Steps to set up the Master for Slave in Jenkins :

  • Click on the Manage Jenkins and new options will be showcased in Mid Pane, so choose Managae Nodes Option
  • Click on the New Node link and provide some stupid name to the node. Donot forget to select the Pemanent Agent option
  • New details page opens, upon Clicking Ok button
    • # of executors : Decides number of Jobs can execute at any time in the node (Nothing but how many paralles should run)
    • Remote root directory : We have to set the folder, where we want to store the settings of the Jenkins node
  • we have to setup the Method of onvocation of the Node machine. When you are using for the first time you might not find the exact option. So first save the current configuration
  • Let create the simple way to invoke the node using the Jekins Slave Jar
  • Click on Manage Jenkins >> Configure Global Security >> Select Random Option under Agents category
  • Now you should be able to see the Node in Offline Condition
  • Now click on it, On the configuration you should be able to see Launch agent via Java Web Start option for Launch Method. Choose that option and save it
  • Enter Remote Home value into Custom WorkDir Path

Steps to set up the Slave for Master in Jenkins :

  • Open the Node Machine ( could be another physical machine or vitual machine )
    • [Optional] Now you should have the ip address of the Master machine to configure the jenkins. You can get the IP address of the Computer by Typing ipconfig on the Command Prompt
    • Copy the IPv4 Address ( Sorry for masking two numbers)
  • Now click the Node that we have created sometime back
  • Click on the Launch Button, Now a A file called slave-agent will be downloaded
  • Double click the downloaded the jar file
  • Now you should be able to few popups and accept them. If you accept the you will see A guy with tie with connected message
  • Now Go to your Master and Click on the Build Executor status
  • You should be able see the node in online (no offline mode)

Maven Project in Jenkins

hyper-virtual-machine create-virtual-machine-windows-10 specify-vm-generation configure-vm-win-10

About Author

Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know. Knowledge is the only thing that doubles when you spend it.

I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions