Deploying JMeter and Ant on Ubuntu for Continuous Integration
To set up JMeter and Ant for automated enterface testing in a Jenkins container, follow these steps to install and configure the necessary components on Ubuntu.
Installing JDK on Ubuntu
-
Download the JDK package, such as
jdk-8u74-linux-x64.tar.gz, and transfer it to the server usinglrzsz. Installlrzszwithsudo apt-get install lrzsz. Userzto upload files from your local machine to the server andszto download files from the server. -
Extract the JDK archive. Run
tar -xvf jdk-8u74-linux-x64.tar.gzto create a directroy likejdk1.8.0_74. -
Configure environment variables. Edit
/etc/profilewithviand add:export JAVA_HOME=/usr/local/java/jdk1.8.0_74 export PATH=$JAVA_HOME/bin:$PATHApply the changes with
source /etc/profile. -
Verify the installation by running
java -version.
Installing JMeter
-
Package the local JMeter files into a ZIP archive, such as
apache-jmeter-3.2.zip, and upload it to the server usingrz. -
Install
unzipif not present:apt-get install unzip. -
Extract the archive with
unzip apache-jmeter-3.2.zip, resulting in a directory likeapache-jmeter-3.2. -
Move the extracted directory to
/usr/local. -
Set JMeter environment variables. Edit
/etc/profileand add:export JMETER=/usr/local/apache-jmeter-3.2 export PATH=$JMETER/bin:$PATHExecute
source /etc/profileto activate. -
Check the setup by running
jmeter -v.
Testing JMeter Scripts
Run a JMeter script in non-GUI mode with:
jmeter -n -t /tmp/apache-jmeter-3.2/bin/lsmsp.jmx -l log.jtl
Parameters:
-n: Run without GUI-t: Specify the script file-l: Define the output log file
View results with cat log.jtl.
Enstalling Ant on Ubuntu
-
Install Apache Ant, such as
apache-ant-1.9.9, in/usr/localusing a similar method as JMeter. -
Configure Ant environment variables. Edit
/etc/profileand append:export ANT_HOME=/usr/local/apache-ant-1.9.9 export PATH=$ANT_HOME/bin:$PATHApply with
source /etc/profileand verify withant -v. -
Copy
ant-jmeter-1.1.3.jarfromjmeter/extrastoant/lib.
Configuring build.xml for Ant
Create a build.xml file to automate JMeter test execution with Ant. Two approaches are outlined below.
Option 1: Direct Script Execution This method runs scripts stored locally in the JMeter directory.
<?xml version="1.0" encoding="UTF-8"?>
<project name="jmeter-ant-run" default="execute" basedir=".">
<tstamp>
<format property="timestamp" pattern="yyyyMMddHHmm" />
</tstamp>
<property environment="sysenv"/>
<property name="reportTitle" value="PerformanceTest" />
<property name="jmeter.install" value="/usr/local/apache-jmeter-3.2" />
<property name="jmeter.result.jtl" value="${sysenv.WORKSPACE}/output/${sysenv.BUILD_ID}/${sysenv.BUILD_ID}.jtl" />
<property name="jmeter.result.html" value="${sysenv.WORKSPACE}/output/${sysenv.BUILD_ID}/${sysenv.BUILD_ID}.html" />
<target name="execute">
<echo message="Initiating test..."/>
<antcall target="setup" />
<antcall target="runTests" />
<antcall target="generateReport" />
</target>
<target name="setup">
<mkdir dir="${sysenv.WORKSPACE}/output/${sysenv.BUILD_ID}" />
</target>
<target name="runTests">
<taskdef name="jmeterTask" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
<jmeterTask jmeterhome="${jmeter.install}" resultlog="${jmeter.result.jtl}">
<testplans dir="/usr/local/apache-jmeter-3.2/bin/testScripts" includes="sample.jmx" />
<property name="jmeter.save.saveservice.output_format" value="xml"/>
</jmeterTask>
</target>
<target name="generateReport">
<xslt in="${jmeter.result.jtl}"
out="${jmeter.result.html}"
style="${jmeter.install}/extras/jmeter-results-detail-report_21.xsl" />
</target>
</project>
Option 2: Git-Based Script Retrieval This approach fetches scripts from a Git repository before execution.
<?xml version="1.0" encoding="UTF-8"?>
<project name="jmeter-git-ant" default="launch" basedir=".">
<tstamp>
<format property="currentTime" pattern="yyyyMMddHHmm" />
</tstamp>
<property environment="envVars"/>
<property name="reportName" value="TestSummary" />
<property name="jmeter.path" value="/usr/local/apache-jmeter-3.2" />
<property name="result.dir" value="/usr/local/apache-jmeter-3.2/results/${envVars.BUILD_ID}" />
<property name="result.jtl" value="${result.dir}/${reportName}.jtl" />
<property name="result.html" value="${result.dir}/${reportName}.html" />
<property name="git.local" value="${envVars.WORKSPACE}" />
<target name="launch">
<echo message="Starting process..."/>
<antcall target="prepare" />
<antcall target="executeTests" />
<antcall target="createReport" />
</target>
<target name="prepare">
<mkdir dir="${envVars.WORKSPACE}/results/${envVars.BUILD_ID}" />
</target>
<target name="executeTests">
<taskdef name="jmeterExec" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
<jmeterExec jmeterhome="${jmeter.path}" resultlog="${result.jtl}">
<testplans dir="${git.local}" includes="demo.jmx" />
<property name="jmeter.save.saveservice.output_format" value="xml"/>
</jmeterExec>
</target>
<path id="xslt.classpath">
<fileset dir="${jmeter.path}/lib" includes="xalan*.jar"/>
<fileset dir="${jmeter.path}/lib" includes="serializer*.jar"/>
</path>
<target name="createReport">
<tstamp>
<format property="reportDate" pattern="yyyy/MM/dd HH:mm" />
</tstamp>
<xslt classpathref="xslt.classpath"
force="true"
in="${result.jtl}"
out="${result.html}"
style="${jmeter.path}/extras/jmeter.results.shanhe.me.xsl">
<param name="dateReport" expression="${reportDate}"/>
</xslt>
<copy todir="${result.dir}">
<fileset dir="${jmeter.path}/extras">
<include name="collapse.png" />
<include name="expand.png" />
</fileset>
</copy>
</target>
</project>