首页 > 解决方案 > 根据先前任务日志中的字符串有条件地运行 Azure DevOps 任务

问题描述

我有一个运行几个 JMeter 测试和一些 Powershell 脚本的 CI 管道。

如果 JMeter 测试失败,它仍会在 DevOps 中报告为成功。

但是,日志会显示“Err:”,然后是测试中失败的调用次数。

如果“运行出站电子邮件 JMeter 测试”任务已完成且日志中不包含“Err:”,我如何才能仅运行以下任务(写入线程引用)?

在此处输入图像描述

标签: azure-devopsjmeter

解决方案


I think the better option would be failing the whole "Run Outbound Email JMeter Test" task so if there are failures it would return non-zero exit status code so the pipeline would "catch" it

For example you can run your test using JMeter Maven Plugin, the simple pom.xml would be something like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>jmeter-maven</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <!-- Generate JMeter configuration -->
                    <execution>
                        <id>configuration</id>
                        <goals>
                            <goal>configure</goal>
                        </goals>
                    </execution>
                    <!-- Run JMeter tests -->
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                    <!-- Fail build on errors in test -->
                    <execution>
                        <id>jmeter-check-results</id>
                        <goals>
                            <goal>results</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

And output:

enter image description here

Alternatively you can use Taurus automation framework which has Pass/Fail criteria subsystem

Example configuration:

execution:
- scenario: simple

scenarios:
  simple:
    script: test.jmx

reporting:
- module: passfail
  criteria:
  - succ<100%, continue as failed

and output:

enter image description here


推荐阅读