How to run JMeter with Jenkins


In this article, you will learn how to run JMeter with Jenkins. This an important step in order to be able to achieve continuous integration (CI).

Table of contents

Introduction

So, you have created your first JMeter test and are now wondering how you can make it part of your CI pipeline. Well, you have come to the right place. In this tutorial you are going to learn how to run your JMeter tests on Jenkins using Maven. It is assumed that you already know how to use JMeter and can create a Maven project.

Creating a JMeter test

Once you have a JMeter test, you may want to pass in parameters from the command line or from Jenkins at run time. Let’s assume that you want to specify the number of threads, ramp-up period and loop count. This is done by using a property function.

JMeter Thread Group
JMeter Thread Group

Click here to learn more about the __P property function.

As shown above, the three properties have been added, namely thread, rampUp and loopCount. The “1” after the property name indicates a default value. For instance, if no threads are specified when the test runs, the test will default to running with one thread.

Setting up a Maven project

Once your project is set up, you will need to edit its pom.xml file to tell Maven how to run the JMeter tests. You will add the JMeter Maven plugin, the name of the JMeter file (.jmx) and any user properties. When finished, the pom file should look something like this:

JMeter Maven Jenkins Project
JMeter Maven Jenkins Project

At the time of writing, the above shows the latest version for each plugin. In the future, you may need to update the versions accordingly.

The next thing you will need to do is to create a folder called jmeter inside src/test in the Maven project and place the .jmx file in that folder. Also, you need to verify that the pom.xml file has automatically been placed at the same hierarchy level as the src folder when the project was initially created. Please refer to the image below.

pom.xml file location and .jmx file location

Running JMeter from the command line

Here is the command to run the test directly from the command line:

mvn clean -Dthreads=3 -DrampUP=3 -DloopCount=2 verify

As you can see, this command tells Maven to run the test with 3 threads, 3 seconds ramp up period and a loop count of 2. A successful build will look like this:

running jmeter from command line

Running JMeter from Jenkins

Lastly, you will create a Jenkins project to run the JMeter test.

  • In Jenkins, click New Item, give your project a name, select Freestyle project and click OK
creating a Jenkins project
  • Click This project is parameterized in the project’s configuration screen
  • Click Add Parameter drop down menu and select String Parameter
  • Enter THREADS in the Name field (you may also enter a Default Value)
  • Create two more parameters, RAMP_UP and LOOP_COUNT by following the same steps 
setting up a jmeter project in jenkins
  • In the Build section, click the Add build step drop down and select Invoke top-level Maven targets
  • Set the Goals field as follows
setting up a jmeter project in jenkins
  • Click Save
  • Click Build with Parameters, your screen should look as follows
running up a jmeter project in jenkins
  • Enter some values for each of the fields (or leave some of the fields blank)
  • Click Build

The build should be successful. Any blank fields should be substituted by corresponding default values as specified in the JMeter file.

Congratulations, you can now run your JMeter tests on Jenkins and even take it a step further by adding reporting capabilities using the Jenkins JMeter plugin. Have fun! 

Leave a Reply