Continuous Integration (CI) is an essential part of the software development lifecycle (SDLC) as it automates software build, testing, and deployment processes, and performance monitoring is a key part of CI. Implementing CI helps in:
- Monitor source code repositories.
- Run builds whenever code changes are detected.
- Run tests against compiled software (unit, acceptance, automated, performance, integration).
- Generate artifacts (binaries, documentation, installation packages).
Adding testing in CI process helps in reducing performance issues before and after adding (or) making changes in code builds of your software application. As main motto of CI process is to detect any integration related issues as early as possible. Now, let's consider Jenkins as Continuous Integration tool and JMeter tool for load testing.
Download and Install Jenkins:
- Download latest release of Jenkins (download .war file).
- Now run Jenkins as java - jar jenkins.war (give path of jenkins.war file). You can find "Jenkins is fully up and running" message.
- Open your web browser and give http://localhost:8080 URL.
- You can find this page asking to enter the password to unlock.
- Go to secrets folder which will be in .jenkins folder in your system and open initialAdminPassword and copy the password which was present.
- Paste the password in the browser and say continue
- After on click Continue , you can a find that its asking for suggested plugins or select your plugins to integrate choose accordingly.
- After the plugins got installed, it will ask to create an Admin User. You can select either continue as Admin (or) Save and continue .
- Great! your Jenkins setup is done. And, it is ready.
- You will find Jenkins dashboard as below:
After completing the above setup we will see now how to setup JMeter with Jenkins for performing a load test.
Download and Install Jenkins:
- We need Performance Plugin (download the latest release) to get JMeter support.
- Copy the downloaded performance.hpi file to plugins of .jenkins folder.
- Now Restart the Jenkins to pick up this plugin.
- Now you can find Publish Performance Test Result Report option under Jenkins >> Your Project >> Configure >> Add post-build action from dropdown .
- As Publish Performance Test Result Report generates the average, median and 90 percentile values along with the errors count of each build. Also it compares the build with the previous builds.
- If your latest build inadvertently causes response times to go above an acceptable threshold or SLA, your CI system will automatically raise a 'red flag' and mark the build as 'failed' . This helps in finding out the cause of the problem.
JMeter test with Jenkins:
- After setting up the entire above configuration, now we will start a JMeter test with Jenkins. We need Non-GUI mode to run test.
- Before starting the test go to user.properties and set jmeter.save.saveservice.output_format=xml or you send it through command line arguments as -Jjmeter.save.saveservice.output_format=xml
- Now go to your Jenkins dashboard and select New Item and name it accordingly. And select the project type from the below list and click OK .
- After clicking OK, we can see the configuration page of the build item as below:
- Configure all steps required for your project accordingly and in Post Steps >> Add post-build action; select Execute Windows batch command .
- And pass command line arguments as path to apache jmeter - bin\jmeter.bat -Jjmeter.save.saveservice.output_format=xml -n -t SampleTest.jmx -l test1.jtl to start the JMeter test..
- Now we will use the Performance Plugin to get the statistics of the build go to Post-build Actions >> Add post-build action >> Publish Performance test result report and give the .jtl file name and save it.
- We can find the project has created and select Build Now to start the test.
- To check the execution of the test go to Console Output of the build you can see the summary report of your JMeter test. And you can find log and .jtl results file under your project.
- Also Jenkins allows you to build parameters for your JMeter test by selecting This project is parameterised check box.
Now you have automated the performance testing, you can spend more time on improving your software instead of struggling with identifying performance problems.