Jmeter(maven)不是在jenkins上运行,而是在本地运行

时间:2018-08-24 20:38:03

标签: maven jenkins jmeter jmeter-maven-plugin

我创建了一个测试项目(Maven)以测试REST API的性能。我正在使用Jmeter插件

这是我的pom片段

<build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.5.0</version>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <resultsDirectory>/tmp/jmeter</resultsDirectory>
                </configuration>
            </plugin>
        </plugins>
 </build>

我的项目中有一个这样的JenkinsFile

pipeline {
   agent any

environment {
    BRANCH_NAME = "${env.PIPELINE_BRANCH_NAME}"
}

stages {
    stage('SCM checkout') {
        steps {
           .......
        }
    }

    stage('Execute Jmeter tests') {
        steps {
            echo '****************************************\r*** Execute Jmeter tests'
            withMaven(jdk: 'JDK 8', maven: 'aer Maven 3') {
                sh 'mvn jmeter:jmeter'
                performanceReport parsers: [[$class: 'JMeterParser', glob: '/tmp/jmeter/**/*.jtl']], sourceDataFiles: "/tmp/jmeter/*.jtl", modePerformancePerTestCase: true, failBuildIfNoResultFile:true
            }
        }
    }
  }
}

有了这个,当我在Jenkins上触发构建时,构建成功,并且在控制台输出中看到了

.......
[INFO] Creating summariser <summary>
[INFO] Created the tree successfully using /mypath/....../testFiles/mytest.jmx
[INFO] Starting the test @ Fri Aug 24 21:51:37 CEST 2018 (1535140297393)
[INFO] Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
[INFO] summary =      0 in 00:00:00 = ******/s Avg:     0 Min: 9223372036854775807 Max: -9223372036854775808 Err:     0 (0.00%)
[INFO] Tidying up ...    @ Fri Aug 24 21:51:40 CEST 2018 (1535140300073)
[INFO] ... end of run
[INFO] Completed Test: /global/otdci/apps/build_server/jenkins/jobs/SCMAER/jobs/SCMAER-TEST-performancetesting/workspace/target/jmeter/testFiles/MaterialGroup.jmx
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.012 s
[INFO] Finished at: 2018-08-24T21:51:40+02:00
[INFO] Final Memory: 20M/615M
[INFO] ---------------------------------------------

问题是,它什么也没做。 Performace趋势图不显示任何内容。

如果我在本地计算机上运行相同的项目,则可以正常运行。我在日志中看到类似的内容,这证实了这一点。并且生成的输出文件(.jtl文件)也是正确的。

[INFO] Starting the test @ Fri Aug 24 22:02:21 CEST 2018 (1535140941482)
[INFO] Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
[INFO] summary +    177 in 00:00:08 =   21.2/s Avg:   184 Min:   117 Max:  1366 Err:     0 (0.00%) Active: 5 Started: 5 Finished: 0
[INFO] summary +    910 in 00:00:30 =   30.4/s Avg:   165 Min:   115 Max:  3205 Err:     0 (0.00%) Active: 5 Started: 5 Finished: 0
[INFO] summary =   1087 in 00:00:38 =   28.4/s Avg:   168 Min:   115 Max:  3205 Err:     0 (0.00%)
[INFO] summary +    964 in 00:00:30 =   32.1/s Avg:   154 Min:   110 Max:  3193 Err:     0 (0.00%) Active: 5 Started: 5 Finished: 0
[INFO] summary =   2051 in 00:01:08 =   30.0/s Avg:   162 Min:   110 Max:  3205 Err:     0 (0.00%)
[INFO] summary +    966 in 00:00:30 =   32.1/s Avg:   156 Min:   113 Max:  3199 Err:     0 (0.00%) Active: 5 Started: 5 Finished: 0
[INFO] summary =   3017 in 00:01:38 =   30.7/s Avg:   160 Min:   110 Max:  3205 Err:     0 (0.00%)
[INFO] summary +    948 in 00:00:30 =   31.7/s Avg:   157 Min:   114 Max:  3194 Err:     0 (0.00%) Active: 5 Started: 5 Finished: 0
[INFO] summary =   3965 in 00:02:08 =   30.9/s Avg:   159 Min:   110 Max:  3205 Err:     0 (0.00%)
[INFO] summary +    862 in 00:00:30 =   28.6/s Avg:   170 Min:   115 Max:  3226 Err:     0 (0.00%) Active: 5 Started: 5 Finished: 0
[INFO] summary =   4827 in 00:02:38 =   30.5/s Avg:   161 Min:   110 Max:  3226 Err:     0 (0.00%)
[INFO] summary +    185 in 00:00:06 =   30.1/s Avg:   178 Min:   115 Max:  3191 Err:     0 (0.00%) Active: 0 Started: 5 Finished: 5
[INFO] summary =   5012 in 00:02:45 =   30.5/s Avg:   162 Min:   110 Max:  3226 Err:     0 (0.00%)
[INFO] Tidying up ...    @ Fri Aug 24 22:05:06 CEST 2018 (1535141106249)
[INFO] ... end of run

这是我的测试计划的摘要

enter image description here 知道为什么它不能在詹金斯上运行吗?有任何指针可以调试吗?

1 个答案:

答案 0 :(得分:1)

面向面临相同问题的任何人。这是解决方案以及如何找到它。

确实,问题很简单。在我的测试计划(jmx)中,我使用的是csv文件作为“ CSV数据集配置”。我已经放了这样的东西

  

inputFiles \ materialstamm.csv

这在我的本地计算机上可以正常运行,因为我在Windows上运行。而且它在Jenkins上不起作用,因为它是Unix计算机。我将其更改为

  

inputFiles / materialstamm.csv

我的jenkins版本开始正确运行。

现在到了找出问题的地步。这非常困难,因为Jmeter在构建过程中未报告任何内容。即使我启用了Maven调试。

由于无法加载我的数据集(通过csv文件),因此它只是跳过此过程并假定没有数据,并且最终以成功状态生成,但没有任何报告/结果。

诀窍是寻找Jmeter日志文件。 Jmeter生成的日志文件位于 .... / workspace / target / jmeter / logs / testplanname.log

但是我没有对jenkins机器的控制台访问权限,而且在Jenkins UI上,默认情况下我也没有看到工作区文件夹。 This  答案帮助我获得了工作区文件夹。当我检查那里的日志时,它清晰可见,因为jmeter抛出异常,说找不到csv文件。