首页 > 解决方案 > 如何将 SonarQube 和 JMeter 与 AWS CodeBuild 集成

问题描述

我们如何将 SonarQube 和 JMeter 与 AWS CodeBuild 集成。

目前我们在 bitbucket 中使用源代码并使用 aws codebuild 构建代码。那么对于这个 cicd 进程如何设置 sonarqube 和 jmeter?

标签: node.jsamazon-web-servicesjmetersonarqubedevops

解决方案


根据JMeter 项目主页

Apache JMeter™ 应用程序是开源软件,一个 100% 纯 Java 应用程序,旨在加载测试功能行为和测量性能。它最初是为测试 Web 应用程序而设计的,但后来扩展到其他测试功能。

因此,您需要一个Java VM实例才能运行 JMeter,因此您需要java AWS CodeBuild 映像

运行 JMeter 有多种选择,但可能最简单的一种是使用JMeter Maven Plugin,如果您将拥有像这样的pom.xml 文件

<?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>untitled</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>

并将您的 JMeter 测试放入src/test/jmeter相对于 pom.xml 文件的文件夹中,您将能够使用 Maven n触发 JMeter 测试,如下所示:

build:
 commands:
   - mvn verify

推荐阅读