Simple example of jmeter+ant+jenkins

1. Environment installation

  1.jmeter

    First install the java environment, configure JAVA_HOME, PATH, CLASS_PATH and other paths, then go to the official website to download jmeter, configure JMETER_HOME, PATH and other environments, you can download it by yourself to ensure that jmeter can start normally

  2.ant

    After downloading ant from the official website, install it, configure ANT_HOME, PATH, CLASS_PATH and other paths, and enter ant if there is content, it means the configuration is successful

  3. Put the jar package of ant-jmeter-1.1.1 under \apache-jmeter-3.2\extras to the lib directory of ant, this step is very important, otherwise ant cannot adjust jmeter

  4. Configure jenkins, after downloading the jenkins package from the official website, run the command java -jar jenkins, the default port is 8080, and then open http://127.0.0.1:8080 with a browser, the configuration of jenkins will appear, and you can configure it as required

2. The above configuration is more troublesome, and there can be no mistakes. Fortunately, there are still many tutorials on the Internet. It should be no problem under Baidu. Ant will execute the build.xml file in the current folder by default, and create a new build.xml file. I It is placed under E:\jmeter\apache-jmeter-3.1\demo, first write the jmx file with jmeter

 

The content in build.xml is as follows

<?xml version="1.0" encoding="UTF-8"?>

-<project basedir="." default="run" name="ant-jmeter-test">     


-<tstamp>

<format pattern="yyyyMMddhhmm" property="time"/>

</tstamp>

<!-- Need to change to your own local Jmeter directory -->  

<property name="jmeter.home" value="E:\jmeter\apache-jmeter-3.1"/>

<!-- The path where jmeter generates the result report in jtl format-->

<property name="jmeter.result.jtl.dir" value="E:\jmeter\apache-jmeter-3.1\demo\report\jtl"/>

<!-- The path where jmeter generates the result report in html format-->

<property name="jmeter.result.html.dir" value="E:\jmeter\apache-jmeter-3.1\demo\report\html"/>

<!-- Prefix of generated report -->

<property name="ReportName" value="TestReport"/>

<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl"/>

<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html"/>


-<target name="run">

<antcall target="test"/>

<antcall target="report"/>

</target>


-<target name="test">

<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>


-<jmeter resultlog="${jmeter.result.jtlName}" jmeterhome="${jmeter.home}">

<!-- Declare a script to run. "*.jmx" refers to include all jmeter scripts in this directory -->

<testplans dir="E:\jmeter\apache-jmeter-3.1\demo" includes="*.jmx"/>

<property name="jmeter.save.saveservice.output_format" value="xml"/>

</jmeter>

</target>


-<path id="xslt.classpath">

<fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>

<fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>

</path>


-<target name="report">


-<tstamp>

<format pattern="yyyy/MM/dd HH:mm" property="report.datestamp"/>

</tstamp>

<!-- Pay attention to the style attribute below, this is the format file in extras under jmeter, you can change the output html format by changing this -->


-<xslt style="${jmeter.home}/extras/jmeter-result-detail-report.xsl" out="${jmeter.result.htmlName}" in="${jmeter.result.jtlName}" force="true" classpathref="xslt.classpath">

<param name="dateReport" expression="${report.datestamp}"/>

</xslt>


-<copy todir="${jmeter.result.html.dir}">


-<fileset dir="${jmeter.home}/extras">

<include name="collapse.png"/>

<include name="expand.png"/>

</fileset>

</copy>

</target>

</project>

 

The above build configures the information of the running jmx file, as well as the format and save location of the result, etc. You can modify it according to your own needs. After saving, enter the current folder and run ant:

After running successfully, you can find the running results in the current folder

 

ok, you're done, indicating that ant can successfully run jmeter and save the results

3. Use jenkins

Jenkins will not be introduced much, here is mainly to help you run the jmeter script every once in a while, configure the PATH first, click on the build execution status -> master -> configure the slave node -> environment variables, add your PATH, here It is equivalent to the computer configuration environment variable

 

 

 One thing to pay attention to here is the configuration of ANT_HOME. Sometimes ANT_HOME cannot be recognized. Just replace it with an absolute path. For example, mine is E:\jmeter\apache-ant-1.10.3

Then go back to the home page -> New task -> create a free style project, select Invoke ant in the build, put your build file in it

Then configure the build trigger and set it to execute every 5 minutes

After saving, click Build Now, you will see a lot of small blue, red means failure

Click on the little blue -> console output, you can see your running results

 

 

 Then you can go to your results folder to view

 

So far, a simple script has been written, let's review: installation environment (more troublesome, one step can not be wrong), write build and jmx files (specify the location of the file, the location and format of the result), configure jenkins , just like putting elephants in the refrigerator, also in three steps

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325237144&siteId=291194637