Search code examples
mavenjmeterjmeter-maven-plugin

How to set the Jmeter properties in xml file


I am using below JMeter maven plugin in my POM.XML

<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.7.0</version>

And if I want to execute the JMX file using maven command I updated my pom.xml file with below tags

Outside of my build block

<properties>
<my.host>localhost</my.host>
</properties>

in configuration block

<configuration>                       
<propertiesUser> 
<hostName>${my.host}</hostName> 
</propertiesUser> 
</configuration> 

I run using below command to run JMeter using MVN

mvn verify  -Dmy.host=www.test.com

But I am not able to see the changes in my command window when I above command so is there anything that I want to add in my JMX file to run this command.


Solution

  • Your configuration looks good and you should be able to refer the property value via __P() or __property() functions where required.

    If you want to print the property value to the console where you run Maven - you can go for __groovy() function. The relevant code will be something like:

    ${__groovy(println('Current hostName value:'+ props.get('hostName')),)}
    

    And the output will be:

    JMeter Maven Property

    See Apache JMeter Functions - An Introduction to learn more about JMeter Functions concept.