Gitlab CI报告Jmeter测试失败

时间:2018-10-23 14:16:46

标签: jmeter gitlab-ci gitlab-ci-runner jmeter-maven-plugin

我们在Jmeter + Maven集成项目中有Gitlab的工作。它将执行.jmx文件并生成jmeter仪表板报告并发送邮件。以下是我的yml文件

[INFO] -------------------------------------------------------
[INFO]  P E R F O R M A N C E    T E S T S
[INFO] -------------------------------------------------------
[INFO]  
[INFO]  
[INFO] Executing test: Master_BPM_APIs.jmx
[INFO] Starting process with:[java, -Xms512M, -Xmx512M, -jar, ApacheJMeter- 
4.0.jar, -d, /home/gitlab-runner/builds/af1bddbf/0/sip-jbpm6-5/bpm-api- 
automation/target/jmeter, -e, -j, /home/gitlab-runner/builds/af1bddbf/0/sip- 
jbpm6-5/bpm-api-automation/target/jmeter/logs/Master_BPM_APIs.jmx.log, -l, 
/home/gitlab-runner/builds/af1bddbf/0/sip-jbpm6-5/bpm-api- 
automation/target/jmeter/results/Master_BPM_APIs.csv, -n, -o, /home/gitlab- 
runner/builds/af1bddbf/0/sip-jbpm6-5/bpm-api- 
automation/target/jmeter/reports/Master_BPM_APIs_20181023_164847, -t, 
/home/gitlab-runner/builds/af1bddbf/0/sip-jbpm6-5/bpm-api- 
automation/target/jmeter/testFiles/Master_BPM_APIs.jmx]
[INFO] Creating summariser <summary>
[INFO] Created the tree successfully using /home/gitlab- 
runner/builds/af1bddbf/0/sip-jbpm6-5/bpm-api- 
automation/target/jmeter/testFiles/Master_BPM_APIs.jmx
[INFO] Starting the test @ Tue Oct 23 16:48:50 IST 2018 (1540293530191)
[INFO] Waiting for possible Shutdown/StopTestNow/Heapdump message on port 
4445
[INFO] 1
[INFO] summary =      8 in 00:00:02 =    4.6/s Avg:    82 Min:     2 Max:   
207 Err:     1 (12.50%)
[INFO] Tidying up ...    @ Tue Oct 23 16:48:52 IST 2018 (1540293532577)
[INFO] ... end of run
[INFO] Completed Test: /home/gitlab-runner/builds/af1bddbf/0/sip-jbpm6- 
5/bpm-api-automation/target/jmeter/testFiles/Master_BPM_APIs.jmx
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ bpm-api- 
automation ---
[INFO] Installing /home/gitlab-runner/builds/af1bddbf/0/sip-jbpm6-5/bpm-api- 
automation/target/bpm-api-automation-0.0.1-SNAPSHOT.jar to /home/gitlab- 
runner/.m2/repository/com/causeway/bpm/bpm-api-automation/0.0.1- 
SNAPSHOT/bpm-api-automation-0.0.1-SNAPSHOT.jar
[INFO] Installing /home/gitlab-runner/builds/af1bddbf/0/sip-jbpm6-5/bpm-api- 
automation/pom.xml to /home/gitlab- 
runner/.m2/repository/com/causeway/bpm/bpm-api-automation/0.0.1- 
SNAPSHOT/bpm-api-automation-0.0.1-SNAPSHOT.pom
[INFO] --------------------------------------------------------------------- 
 ---
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------------------- 
 ---
[INFO] Total time: 11.011 s
[INFO] Finished at: 2018-10-23T16:48:54+05:30
[INFO] --------------------------------------------------------------------- 
 ---
[INFO] Shutdown detected, destroying JMeter process...
[32;1m$ echo "-------------------Execution completed---------"[0;m
-------------------Execution completed---------

以下是输出:

label

但是我们需要的是如果有任何错误/测试失败,则构建应该设置为失败或返回构建状态0或1,并在作业日志控制台中返回完整错误

1 个答案:

答案 0 :(得分:0)

  1. 如果您将下一个块添加到 pom.xml 文件中,则您已经在使用Jmeter Maven插件:

    <execution>
         <id>jmeter-check-results</id>
         <goals>
             <goal>results</goal>
         </goals>
    </execution>
    

    Maven构建将被标记为失败,从而导致整个Gitlab CI作业失败。

    enter image description here

  2. 您可以切换到Taurus工具,该工具提供了强大而灵活的Pass/Fail Criteria subsystem,可让您使用简单的声明性语句(例如

    )来定义如何处理故障
    - avg-rt of IndexPage>150ms for 10s, stop as failed
    - fail of CheckoutPage>50% for 10s, stop as failed
    

    因此,如果(如果)符合标准,金牛座将返回非零退出代码

  3. 仅JMeter的解决方案:您可以使用以下代码添加一个JSR223 Listener

    if (prev.isSuccessful()) {
        System.exit(-1)
    }
    

    它将返回-1退出状态到父进程,但是在这种情况下.jtl结果文件可能不完整或损坏