[Jenkins] 壓測腳本搭建Jmeter小筆記

Ref:
[基于Jmeter和Jenkins搭建性能测试框架]
https://blog.csdn.net/liuchunming033/article/details/52186157

性能测试框架工作的流程主要有:

–>触发测试
–>部署测试脚本
–>部署被测系统
–>Jmeter打压
–>被测系统日志分析
–>◎


Jenkins Plugin配置

1. Performance Plugin: 解析Jmeter生成的测试报告,直观的展示出来。
->如果安装正确,在性能测试job的配置页面的 “Add post-build action” 步骤里面能够看到 “Publish Performance Test Result Report” 选项。
3.
4.
5.
6.

Jmeter
(下载地址:http://jmeter.apache.org/download_jmeter.cgi
解压到目录/usr/local
下载jmeter-plugins插件JMeterPlugins-Standard-1.2.0.zip





另一個可以參考步驟的網站:https://www.blazemeter.com/blog/continuous-integration-101-how-run-jmeter-jenkins

[以下轉貼自BlazeMeter]

How to Install the Jenkins and JMeter Plugin


In this article, I’m assuming that you already have Jenkins up and running somewhere. If you want to experiment, it’s pretty easy to get Jenkins. Here’s how:

1. Download the latest Jenkins release from the https://jenkinsio/ site (note: the .war file should be quite enough)
 
Increase imageJenkins JMeter Plugin

2. Run Jenkins as java -jar jenkins.war and wait for the “Jenkins is fully up and running" message.

Increase imageJenkins Running

3. Open the http://localhost:8080 URL in your favourite browser

4. You should now be able to see the Jenkins dashboard

To get JMeter support on Jenkins, you need to use the Performance Plugin. Once again, it’s really easy to install this plugin. Here’s how:

  1. Download the latest version of the plugin from the Performance Plugin page
  2. Copy the performance.hpi file to the plugins folder of your Jenkins’ installation. If you run Jenkins from the .war file - drop the plugin to the .jenkins/plugins path under your user home folder
  3. Restart Jenkins to pick the plugin up
  4. If everything is fine you should see the “Publish Performance Test Result Report” option under Jenkins -> Your Project -> Configure -> “Add post-build action” dropdown

Increase imageJenkins Performance Report

How to Run a JMeter Test in Jenkins


You’ll be happy to hear that running a JMeter test in Jenkins isn’t very complex. Just remember that the test has to be run in non-GUI mode (check out this article to learn more about running a JMeter test in non-GUI mode).

For your first couple of runs, I recommend “telling” JMeter to store its results in an XML format using one of these approaches:

  1. Add the jmeter.save.saveservice.output_format=xml line to the user.properties file (this is located in /bin folder of your JMeter installation)
  2. Pass the property via the -J command-line argument, such as: C:\jmeter\bin\jmeter.bat -Jjmeter.save.saveservice.output_format=xml -n -t C:\jmeter\extras\Test.jmx -l Test.jtl

You can also use CSV files with the Performance Plugin. However, this requires extra  configuration whereas XML files work fine out of the box.

Here’s how it looks when you configure the Windows batch command to run a JMeter test:

Increase imageRunning a JMeter Test

To verify the execution was successful (or to get extra information regarding any problems), check the “Console Output” tab of the project in question.

Increase imageJenkins Console Output

In the JMeter log file and the .jtl results file, you can find it under the Project’s “Workspace”

Increase imageJenkins Workspace

How to Use the Performance Plugin


The Performance Plugin displays statistics, trends and can also be used to mark builds as failed based on results.

Here’s how you add it:

  1. Open the Jenkins project
  2. Click the “Configure” button
  3. Click the “Add post-build action” button
  4. Select:
-  “JMeter” if your results file is in an XML format
- “JMeterCSV” if your results file is in a CSV format

Increase imageJenkins Performance Test Report

“Report Files” is the main configuration option here. This is the path where the plugin will scan for JMeter results’ files. The format matches the Ant Fileset include/exclude format, and it’s relative to the Jenkins Workspace for the project.

All the other names of the settings here are quite self-explanatory.  

On the first build with the plugin enabled, you’ll see empty charts for the “Performance Trend”.

Increase imageJenkins Performance Trend

The charts will change as you create more builds. They will display average, median and 90 percentile values along with the errors count. The charts are clickable, so you can get more detailed information on each executed sampler.

Passing Jenkins’ Parameters to a JMeter Test


Jenkins allows you to specify build parameters. For example: if you tick the “This build is parameterized” box on the “Configure” page, you’ll be able to set some parameter names along with the default values:

Increase imageJenkins Parameters

This means that you can perform the configuration of your JMeter test without having to change anything in your .JMX script or Ant or Maven configuration.

For instance, if you define the parameter with the name “foo” and the value “bar”,  you can refer to it as:

  • %foo% - if the Jenkins build is executed on a Windows machine
  • $foo  - if the Jenkins build is executed on Linux, Unix, or MacOSX machine

See below for an example of setting a JMeter thread count and accessing it from a JMeter Windows batch command text:

Increase imageJenkins String Parameter


If you run the build once more and take a look into the “Console Output”, you’ll see that the %threads% variable has been changed with the relevant parameter value:

Increase imageJenkins Console Output

Congratulations! You’re now ready to start using JMeter with Jenkins. If you’re a BlazeMeter user, you can use BlazeMeter's Jenkins Plugin to kick off a test in the BlazeMeter cloud directly from Jenkins.

Want to Learn More?



You can also watch our recorded webcast to learn more about how to you can shift your testing into Continuous Integration and Continuous Delivery Processes.  

留言

熱門文章