Wednesday, March 20, 2024

JMeter Integration with Jenkins - CICD | Jmeter Continuous Integration With Jenkins

Overview:

This article provides a comprehensive overview of the seamless integration between Apache JMeter, a popular performance testing tool, and Jenkins, a widely-used automation server for continuous integration and continuous delivery (CI/CD) pipelines. The article elucidates the step-by-step process of configuring Jenkins to execute JMeter tests as part of the CI/CD pipeline, enabling automated performance testing throughout the software development lifecycle. By detailing the setup of Jenkins, installation of necessary plugins, and execution of JMeter tests within Jenkins jobs, the article equips readers with the knowledge to effortlessly incorporate performance testing into their CI/CD workflows. Moreover, it emphasizes the significance of monitoring performance metrics and interpreting test results, thereby empowering teams to ensure the scalability and reliability of their applications in production environments.

Jenkins Setup:

To begin, download the latest stable version of Jenkins from the official website. Once downloaded, navigate to the folder where the Jenkins file is located and execute it using the command `java -jar jenkins.war`.

Please note that Jenkins requires an initial user setup before use. Download the latest Jenkins release from the site (note: the .war file should be quite enough).


Performance Plugin - Installation:

To enable JMeter support on Jenkins, you'll need to install the Performance Plugin. 

1. Download the latest version of the plugin from the Performance Plugin page.
2. Copy the performance.hpi file to the plugins folder of your Jenkins installation. If you're running Jenkins from the .war file, place the plugin in the .jenkins/plugins path under your user home folder.
3. Restart Jenkins to activate the plugin.
4. If the installation was successful, you should now see the “Publish Performance Test Result Report” option under Jenkins -> Your Project -> Configure -> “Add post-build action” dropdown.

or

1. Navigate to your Jenkins dashboard page and click on "Manage Jenkins."
2. From the menu options, select "Plugins."
3. In the Plugins page, switch to the "Available" tab.
4. Enter 'performance' in the search field to find the Performance Plugin.
5. Check the installation checkbox next to the Performance Plugin.
6. Select "Install without restart" to install the plugin without needing to restart Jenkins.

JMeter Installation:

To install JMeter, adhere to these instructions:

1. Visit the Apache JMeter downloadspage.
2. Choose the appropriate download option for your system: .zip for Windows or .tgz for Linux. Since this tutorial is for Linux, the .tgz option is demonstrated.
3. Extract the downloaded file to your desired location, such as /usr/jmeter.
4. Edit the file located at <YOUR-JMETER-PATH>>/bin/user.properties. For instance, usr/jmeter/bin is used in this example.
5. Add the following command to the last line of the file: jmeter.save.saveservice.output_format=xml. Save and close the file to apply the changes.

Create your JMeter script using a GUI:

Here are the steps to create JMeter script:

1. Run the file: `<YOUR-JMETER-PATH>>/bin/jmeter.sh` to open the JMeter GUI. For instance, `/usr/jmeter/bin/jmeter.sh` is used in this example. In a definitive installation, you can set these commands to your path system or system variables. For Windows users, the file will be `jmeter.bat`.
2. From the JMeter GUI, navigate to File, and then select New.
3. Enter a name for your test plan.
4. On the left side of the screen, using the right or secondary select with your mouse, select your test plan. Follow this path: Add > Thread(Users) > Thread Group, and select it.
5. In the Thread Group, increase the Number of Threads (users) to five and the Loop Count to two.
6. On the left side of the screen, right or secondary select Thread Group with your mouse, then follow this path: Add > Sampler > HTTP Request, and select the HTTP Request option.
7. In the HTTP Request, enter the Name of your test, the Server Name or IP, and the Path context.
8. Repeat steps six and seven two more times for different contexts/pages. 
9. To add a visual report, right or secondary select your Thread Group, then follow the path: Add > Listener > View results in table. Select the View Results in Table option.
10. Save the test plan by selecting the Save (disk) icon in the upper left side of the screen or go to File > Save, and enter a name for the test plan with a .jmx extension.


To run the test plan using the command line and integrate it with Jenkins, From the terminal, execute the following commands:

set OUT=jmeter.save.saveservice.output_format
set JMX=/usr/jmeter/bin/easyloadrunner.jmx
set JTL=/usr/jmeter/reports/easyloadrunner.report.jtl
/usr/jmeter/bin/jmeter -j %OUT%=xml -n -t %JMX% -l %JTL%

These commands set up the necessary variables and then execute JMeter with the specified parameters to run the test plan. Adjust the paths and filenames as needed to match your setup.

Execute JMeter Tests With Jenkins:

To execute JMeter from Jenkins and integrate the test results, follow these steps:

1. From the Jenkins dashboard, click on "New Item."
2. Enter a name for the item, for example "JmeterTest", select "Freestyle project", and then click "OK."
3. Go to the "Build Environment" tab, click on "Add build step," and select "Execute Windows batch command."
4. Enter the same code used to run JMeter from the command line in the previous section.

set OUT=jmeter.save.saveservice.output_format
set JMX=/usr/jmeter/bin/easyloadrunner.jmx
set JTL=/usr/jmeter/reports/easyloadrunner.report.jtl
/usr/jmeter/bin/jmeter -j %OUT%=xml -n -t %JMX% -l %JTL%


5. Go to the "Post-build Action" tab, click on "Add post-build action," then select "Publish Performance test result report."
6. Fill in the source for these reports.
7. Save the project, and then click on "Build Now" from the "JmeterTest" page.
8. After the job finishes, navigate to the "Console Output" to view the execution details.
9. From the "Console Output" view, you can access the Performance Report and view the JMeter report data.


#JMeter #Jenkins #CI/CD #ContinuousIntegration #PerformanceTesting #LoadTesting #Automation #DevOps #TestAutomation #JenkinsPipeline #PerformanceTestingAutomation #SoftwareTesting #IntegrationTesting #TestExecution #TestAutomationFramework

No comments: