我准备做 Jenkins+Jmeter+Ant 的接口测试持续集成,但是配置的过程中,一直无法使用 Ant,请大家帮忙看看是什么原因。
系统:Mac OS X EI Capitain 10.11.5
Jenkins: 2.19
Ant 插件:1.3
Ant:1.9.7
Jmeter:3.0
我在本地执行是可以正常执行,而且能生成测试结果的。
SvenWeng@wengyanbin:~/Desktop|⇒ ant
Buildfile: /Users/SvenWeng/Desktop/build.xml
all:
test:
[jmeter] Executing test plan: /Users/SvenWeng/Desktop/Jmeter测试脚本5-2.jmx ==> /Users/SvenWeng/Desktop/TestReport201608280735.jtl
[jmeter] Writing log file to: /Users/SvenWeng/apache-jmeter-3.0/bin/jmeter.log
[jmeter] Creating summariser <summary>
[jmeter] Created the tree successfully using /Users/SvenWeng/Desktop/Jmeter测试脚本5-2.jmx
[jmeter] Starting the test @ Sun Aug 28 19:35:53 CST 2016 (1472384153997)
[jmeter] Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
[jmeter] summary + 1240 in 00:00:06 = 208.3/s Avg: 42 Min: 33 Max: 332 Err: 0 (0.00%) Active: 10 Started: 10 Finished: 0
[jmeter] summary + 2760 in 00:00:13 = 207.4/s Avg: 44 Min: 33 Max: 635 Err: 0 (0.00%) Active: 0 Started: 10 Finished: 10
[jmeter] summary = 4000 in 00:00:19 = 207.7/s Avg: 43 Min: 33 Max: 635 Err: 0 (0.00%)
[jmeter] Tidying up ... @ Sun Aug 28 19:36:13 CST 2016 (1472384173328)
[jmeter] ... end of run
[jmeter] Executing test plan: /Users/SvenWeng/Desktop/推荐码.jmx ==> /Users/SvenWeng/Desktop/TestReport201608280735.jtl
[jmeter] Writing log file to: /Users/SvenWeng/apache-jmeter-3.0/bin/jmeter.log
[jmeter] Creating summariser <summary>
[jmeter] Created the tree successfully using /Users/SvenWeng/Desktop/推荐码.jmx
[jmeter] Starting the test @ Sun Aug 28 19:36:14 CST 2016 (1472384174438)
[jmeter] Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
我首选的是使用 Jenkins 的 Ant 插件来执行我的 build.xml 文件。
报错如下:
ERROR: command execution failed.Maybe you need to configure the job to choose one of your Ant installations?
Finished: FAILURE
看报错应该是我的 Ant 没有配置,但是我查了一下网络上给的解决方案是在 Jenkins 的系统配置中配置 Ant 的环境变量,但是我的 Jenkins 的系统配置里面没有关于 Ant 的。
构建的 Ant 配置如下图
我想使用 shell 来执行脚本,代码如下:
cd /Users/SvenWeng/Desktop
ant
但是执行结果让我很意外,给我报错找不到命令
/Users/Shared/Jenkins/tmp/hudson6252750443925915479.sh: line 3: ant: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
按道理我本地能成功执行,就表示环境变量是配置好的啊,为什么还会出现无法找到命令这个报错?
我的 Python 脚本是这样的:
import os
os.system("ant")
我在本地执行,也是没问题,可以执行成功,但是用 shell 脚本来执行 Python 的时候,报错也是找不到命令。
急需老司机来带带我啊!
放上 build.xml 文件的代码:
<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="all" basedir=".">
<tstamp>
<format property="time" pattern="yyyyMMddhhmm" />
</tstamp>
<!-- 需要改成自己本地的 Jmeter 目录-->
<property name="jmeter.home" value="/Users/SvenWeng/apache-jmeter-3.0" />
<!-- jmeter生成jtl格式的结果报告的路径-->
<property name="jmeter.result.jtl.dir" value="/Users/SvenWeng/Desktop" />
<!-- jmeter生成html格式的结果报告的路径-->
<property name="jmeter.result.html.dir" value="/Users/SvenWeng/Desktop" />
<!-- 生成的报告的前缀-->
<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" />
<path id="javaclass.path">
<pathelement path="${env.classpath}" />
<pathelement path="${env.JBOSS_HOME}/server/all/lib/servlet-api.jar" />
<pathelement path="${env.JBOSS_HOME}/server/all/lib/jsp-api.jar" />
<fileset dir="${tmp.lib}" includes="*.jar" />
<!-- <fileset dir="${project.lib}" includes="*.jar" /> -->
</path>
<target name="all">
<antcall target="test" />
<antcall target="report" />
</target>
<target name="test">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
<!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->
<testplans dir="/Users/SvenWeng/Desktop" includes="*.jmx" />
</jmeter>
</target>
<target name="report">
<xslt in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}" style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" />
<!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 -->
<copy todir="${jmeter.result.html.dir}">
<fileset dir="${jmeter.home}/extras">
<include name="collapse.png" />
<include name="expand.png" />
</fileset>
</copy>
</target>
</project>