You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:如何通过IntelliJ、Maven在Jenkins中运行JMeter脚本

Hey there! Let's get your JMeter workflow with IntelliJ, Maven, and Jenkins fully sorted out based on the steps you've already completed. Here's a step-by-step guide tailored to your setup:

Step 1: Finalize Your Maven Project Structure

First, let's wrap up the file placement you started:

  • Move your create-client.jmx script into a new src/test/jmeter directory (create this folder if it doesn't exist) — this is the default location the jmeter-maven-plugin looks for test scripts.
  • Ensure your report-template folder and reportgenerator.properties file are placed in src/test/resources so Maven can pick them up for report generation.
Step 2: Configure pom.xml for jmeter-maven-plugin

This is the core of integrating JMeter with Maven. Add the following configuration to your project's pom.xml (replace or merge with your existing <build> section):

<build>
    <plugins>
        <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>3.1.0</version> <!-- This version is fully compatible with JMeter 3.3 -->
            <executions>
                <!-- Run JMeter tests -->
                <execution>
                    <id>execute-jmeter-tests</id>
                    <goals>
                        <goal>jmeter</goal>
                    </goals>
                </execution>
                <!-- Generate HTML test report after tests finish -->
                <execution>
                    <id>generate-jmeter-report</id>
                    <goals>
                        <goal>results-report</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- Point to your local JMeter installation -->
                <jmeterHome>C:\Jmeter\apache-jmeter-3.3</jmeterHome>
                <!-- Link your custom report template and config -->
                <propertiesUser>
                    <jmeter.reportgenerator.properties>src/test/resources/reportgenerator.properties</jmeter.reportgenerator.properties>
                    <jmeter.reportgenerator.template.dir>src/test/resources/report-template</jmeter.reportgenerator.template.dir>
                </propertiesUser>
                <!-- Define where test results and reports are saved -->
                <resultsDirectory>${project.build.directory}/jmeter/results</resultsDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>
Step 3: Run JMeter Tests from IntelliJ

Once your pom.xml is set up, you can run tests directly in IntelliJ:

  • Open the Maven panel (usually on the right side of the IDE), expand your project → Plugins → jmeter.
  • Double-click jmeter:jmeter to execute your create-client.jmx script. Test results will be saved to target/jmeter/results.
  • Double-click jmeter:results-report to generate a visual HTML report, which will be stored in target/jmeter/reports.

Alternatively, you can run commands directly in IntelliJ's Terminal:

# Run tests
mvn jmeter:jmeter

# Generate report after tests
mvn jmeter:results-report
Step 4: Integrate with Jenkins

To automate this workflow with Jenkins, follow these steps:

  1. Push your Maven project to a version control system (like Git) first.
  2. For Freestyle Projects:
    • In your Jenkins project, go to Source Code Management and link your Git repository.
    • Add a Build Step → Invoke top-level Maven targets, and enter clean jmeter:jmeter jmeter:results-report as the target.
    • Add a Post-build Action → Publish HTML reports, set the report directory to target/jmeter/reports, and use index.html as the index file.
  3. For Pipeline Projects (recommended for flexibility), use this sample Jenkinsfile:
pipeline {
    agent any
    stages {
        stage('Checkout Code') {
            steps {
                git url: 'your-git-repo-url', branch: 'main'
            }
        }
        stage('Run JMeter Tests') {
            steps {
                sh 'mvn clean jmeter:jmeter jmeter:results-report'
            }
        }
    }
    post {
        always {
            publishHTML target: [
                allowMissing: false,
                alwaysLinkToLastBuild: true,
                keepAll: true,
                reportDir: 'target/jmeter/reports',
                reportFiles: 'index.html',
                reportName: 'JMeter Test Report'
            ]
        }
    }
}
Quick Troubleshooting Tips
  • If the plugin can't find JMeter, double-check the jmeterHome path in pom.xml — or remove this setting entirely to let the plugin auto-download a compatible JMeter version.
  • Avoid absolute paths in your create-client.jmx script (e.g., for CSV files). Use relative paths like ${__P(user.dir)}/src/test/resources/your-data.csv instead.
  • If report generation fails, verify that reportgenerator.properties references the correct path to your report-template folder.

内容的提问来源于stack exchange,提问作者garima

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:39:13