2

我想在 jenkins 上配置 Jmeter 脚本以针对特定线程数运行。让我们说 10 或 20 或 30。我在 Jenkins 中使用 Maven,我如何将线程值作为参数传递,以便每次都可以为 diff 线程运行作业。我正在使用 mvn verify 命令运行 jmeter 文件。

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>jmeter-demo</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>jmeter-demo</name>
    <url>http://maven.apache.org</url>
    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>1.10.1</version>
                <configuration>
                    <testResultsTimestamp>false</testResultsTimestamp>
                </configuration>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
             <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.17</version>
        <configuration>
            <argLine>-Xmx2048m</argLine>
        </configuration>
      </plugin>
        </plugins>
    </build>
</project> 
4

2 回答 2

0

看看维基:

https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/wiki/Modifying-Properties#6

具体来说:

+---+
<project>
    [...]
        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>1.10.1</version>
                    <executions>
                        <execution>
                            <id>jmeter-tests</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                            <configuration>
                                <propertiesGlobal>
                                    <threads>10</threads>
                                    <testIterations>5</testIterations>
                                </propertiesGlobal>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

如果您希望能够在命令行上修改这些属性,您将需要像这样设置 Maven 属性:

+---+
<properties>
    <threads>10</threads>
    <testIterations>5</testIterations>
</properties>

<project>
    [...]
        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>1.10.1</version>
                    <executions>
                        <execution>
                            <id>jmeter-tests</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                            <configuration>
                                <propertiesGlobal>
                                    <threads>${threads}</threads>
                                    <testIterations>${testIterations}</testIterations>
                                </propertiesGlobal>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

然后您将能够像这样指定它们:

mvn clean install -Dthreads=5 -DtestIterations=15
于 2015-09-28T10:37:01.903 回答
0

使用 jmeter-maven-plugin 通过 Maven 运行 JMeter 测试很好,尽管 pom.xml 不是定义线程计数等属性的地方。您正在寻找的是__property__P JMeter 函数。

于 2015-09-26T13:00:00.127 回答