shell+Jenkins+jmeter集成

时间:2023-02-03 14:42:20

参考http://www.cnblogs.com/ceshi2016/p/6025641.html 中除ant相关内容,shell替代ant循环执行jmeter脚本和将jtl转换为html

job name:jmeter_shell,包含多个需要执行的java接口脚本

shell脚本如下:

##!/bin/bash
REPORT_TIME=`date '+%Y%m%d%H%M%S'`
jmeter_basedir=/home/apache-jmeter-2.13
report_icon=$jmeter_basedir/extras/collapse.png
basedir=/var/lib/jenkins/workspace/jmeter_shell
report_jtl=$basedir/report/jtl
report_html=$basedir/report/html
echo "starting..."
cd $report_jtl
rm -f *.jtl
cd $report_html
rm -f  *.html

for v in $(ls /var/lib/jenkins/workspace/jmeter_shell/*.jmx)
do
# REPORT_TIME=`date '+%Y%m%d%H%M%S'`
cd $jmeter_basedir/bin
sh jmeter.sh -n -t $v -l $report_jtl/TestReport_$REPORT_TIME.jtl&
#>~/logs.log &
# xsltproc $jmeter_basedir/extras/jmeter-results-detail-report_21.xsl $report_jtl/TestReport_$REPORT_TIME.jtl > $report_html/TestReport_$REPORT_TIME.html
# sed -i "s/date not defined/$REPORT_TIME/g" grep “date not defined" -l $report_html/TestReport_$REPORT_TIME.html
# if [! -f "$report_icon"];then
# cp $jmeter_basedir/extras/collapse.png $jmeter_basedir/extras/expand.png $report_html
# fi
# if [! -d "$report_jtl"];then
# cd $WORKSPACE/report && mkdir jtl
# fi
sleep 90
#for id1 in $(ps -ef|grep jmeter|awk '{print $2}')
#do
#echo $id1
#kill -l $id1
#done
#sleep 10
done
xsltproc $jmeter_basedir/extras/jmeter-results-detail-report_21.xsl $report_jtl/TestReport_$REPORT_TIME.jtl > $report_html/TestReport_$REPORT_TIME.html

echo "ending..."