Integrate Jmeter With Jenkins and Generate HTML Report
Scripts running in Jmeter could be integrated with Jenkins and can be scheduled to execute at specific time. If Jmeter integrated with Jenkins, then Jmeter interface is not required because Jmeter will execute from command prompt and report will be saved as HTML format.
After following below steps you will learn-
- How to integrate Jemter with Jenkins.
- How to generate HTML report once execution is completed.
Integrate Jmeter With Jenkins:
The basic concept of integrating Jmeter with Jenkins is, first create a project in Jenkins and then configure project to execute Jmeter script.
- Open browser and type localhost:8080 to open Jenkins interface. If you are launching Jenkins first time, it will ask to enter admin password.
- Enter administrator password. Administrator password could be found at C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword
- Open initialAdminPassword file in notepad and copy the text. Paste the text in Administrator password field and click on Continue button.
- If paged lands to Customize Jenkins, then please close with pop up window by clicking on X button shown on right top corner on popup window and Click on Start using Jenkins
- Click on New Item or Create new jobs You can click on any one of the links to create a job.
- Enter any name of your choice in the text box and click on Freestyle project to enable ok button.
- Click on Apply and Save button. (Configuration we will do later)
- Go to C:\ drive and create a folder name JmeterProject (You can give any name).
- Inside folder keep your Jmeter Script. Here I have kept my script name as MyScript.
- Keep downloaded Jmeter Installation folder in C:\ drive. Because we need to provide both the files location in Jenkins, that I will show in below steps.
- Now again go to Jenkins interface and click on MyFirstJenkinsProject link.
- Click on Configure link shown on left side on Jenkins interface.
- Look for Build option and Click on Add build step drop down. Select option Execute Windows batch command.
- Write below command in command box.
cd C:\apache-jmeter-3.1 cd bin jmeter -n -t C:\JmeterProject\MyScript.jmx
- Click on Apply and then Save. Click on Build Now to run the build and execute the Jmeter script. Once you click on Build Now the build will start executing which you can see at left side on Jenkins interface.
Here we have successfully updated the build. If build does not execute or shows in red color, please check file path in Build command.
Here it is just showing build executed but actually script executed or not we are not sure, hence we need to generate one html report which will show the test execution report with sampler executed in Jmeter.
Generate html Report Once Build Successful:
- Go to above step and replace the Build command with below command:
cd C:\apache-jmeter-3.1 cd bin jmeter -n -t C:\JmeterProject\MyScript.jmx -l C:\JmeterProject\output.csv -e -o C:\JmeterProject\HtmlReport
- Click on Apply and Save and Run the build.
- Go to the folder where you have kept Jmeter script. There will be 2 files created – outfile.csv and HtmlReport.
Open HtmlReport folder and open index.html file in Firefox or Chrome browser to view the result.
Note: Every time you execute the build please make sure you have deleted output.csv and HtmlReport folder.