How to create html reports in jenkins of apache jmeter scripts

we will learn about How to run JMeter Script by Jenkins and create HTML report at run time. Before start we should know a basic what Jmeter and Jenkins are? JMeter is an open-source tool basically used for performance and functional testing whereas Jenkins is an automation server and continuous integration tool which is mainly used to automate a project. It provides a number of plugins to automate your projects. With the help of Jenkins, we can configure the Jmeter Script and can also share the Html reports of the test performed on the script.

you can see below video that showing exactly how can you create html report by jenkins.

if you are using ubuntu and your are not Installed Jenkins please Click Here link to download and install jenkins.

Now follow the below steps to run Jmeter script by Jenkins and create Html report for the same.

Step-1 Go to the web browser and run localhost:8080.

Step-2 Before running the script you must have to install Performance Plugin. To do so go to Manage Jenkins >> Manage Plugins >> Available >> Performance plugin and choose to install without restart.

Step-3 In the next step go to Jmeter/bin and add line in user.properties.

jmeter.save.saveservice.output_format=xml

Step-4  In the next step create a Jmeter script. To learn about how to create a Jmeter script Click Here.

Step-5 Now, Run the Jmeter test in Command Prompt or if you are in Ubuntu open terminal.

  • Open the Command Prompt and go to jmeter/bin.
  • Then write the below command and run.

For Windows-

jmeter.bat -Jjmeter.save.saveservice.output_format=xml -n -t D:\Softwares\jmeter\bin\apitest\test.jmx -l D:\Softwares\jmeter\bin\apitest\test.jtl –e –o D:\Softwares\jmeter\bin\apitest\output

For Ubuntu-

sh jmeter.sh -Jjmeter.save.saveservice.output_format=xml -n  -t /Users/Desktop/test.jmx -l /Users/Desktop/test.jtl  -e -o /home/jmeterfiles/report/output

give your folder name where your jmeter and jmx file exist and where you want to save .jtl file.

Step-6 Then add a job in Jenkins. To do so Click on New Item. Name the project as JenkinsJmeterTest and select the type as Freestyle Project and click on OK.

Step-7 In the next step you will automatically redirected to Configure page.

Step-8 Now to create the HTML report add Jmeter Commands in the Build step.You can create both static and dynamic report.But for static report creation for the first time you will be able to create the HTML report but from the second time onwards Jenkins will give you console error because, each an every time it requires empty folder to store the latest build HTML report. To do so follow the below steps-

For Windows

      • Execute Windows Batch Command
      • For Static report creation, write in Command area-
        D:\Softwares\jmeter\bin\jmeter.bat -Jjmeter.save.saveservice.output_format=xml -n -t D:\Softwares\jmeter\bin\apitest\test.jmx -l D:\Softwares\jmeter\bin\apitest\test.jtl –e –o D:\Softwares\jmeter\bin\apitest\output
      • For Dynamic file creation write in Command area-
        D:\Softwares\jmeter\bin\jmeter.bat -Jjmeter.save.saveservice.output_format=xml -n -t D:\Softwares\jmeter\bin\apitest\test.jmx -l D:\Softwares\jmeter\bin\apitest\test.jtl –e –o C:\xampp\htdocs\reports\test
      • In Post Build Actions select Publish Performance Test Result Report and write the jtl file path in source data files i.e. D:\Softwares\jmeter\bin\apitest\test.jtl
    Jenkins build execute windows batch command for windows
    Jenkins build execute windows batch command for windows

    Then fill the details accordingly and click on save.

For Ubuntu

      • Execute Shell
      • For Static report creation, write in Command area-
        sh /home/jmeter/bin/jmeter.sh -Jjmeter.save.saveservice.output_format=xml -Jjmeter.save.saveservice.output_format=csv -n -t /home/jmeterfiles/jmx/test.jmx -l /home/jmeterfiles/jtl/test.jtl -e -o /home/jmeterfiles/report/output
      • For Dynamic file creation write in Command area-
        Jjmeter.save.saveservice.output_format=xml -Jjmeter.save.saveservice.output_format=csv -n -t /home/jmeterfiles/jmx/test.jmx -l /home/jmeterfiles/jtl/${BUILD_ID}.jtl -e -o /var/www/html/report/report${BUILD_ID}
      • In Post Build Actions select Publish Performance Test Result Report and write the jtl file path in source data files i.e./home/jmeterfiles/jtl/test.jtl or /home/jmeterfiles/jtl/${BUILD_ID}.jtl
    Jenkins build execute shell command for ubuntu
    Jenkins build execute shell command for ubuntu

    Then fill the details accordingly and click on save.

Step-9 After that click on Build Now.

Step-10 Run the build and validate the test.

Step-11 Now click on Performance Trend and then click on the Last Report.

Step-12 Now to get the HTML report go to report folder where you save html report that gave you the location in -o and run index file.

HTML report for Jenkins build

For easily view html report you can use apache2 server in Ubuntu and xampp in window and save your html file in server and see from browser.