2

JMeter パフォーマンス テスト計画を条件付きで実行する方法を見つけようとしています。Jenkins CI ジョブで実行したいのですが、開発者が実行するときmvn clean installに以下のプラグインを実行したくありません。pom.xml を変更して、以下のプラグインを条件付きで実行する方法についてのアイデアはありますか?

Maven POM.xml JMeter プラグイン:

<plugin>
    <groupId>com.lazerycode.jmeter</groupId>
        <artifactId>jmeter-maven-plugin</artifactId>
        <version>1.8.1</version>
        <executions>
         <execution>
          <id>jmeter-tests</id>
          <phase>verify</phase>
          <goals>
           <goal>jmeter</goal>
          </goals>
         </execution>
        </executions>
        <configuration>
         <testFilesDirectory>${project.basedir}/src/test/jmeter</testFilesDirectory>
         <ignoreResultFailures>true</ignoreResultFailures>
         <testResultsTimestamp>false</testResultsTimestamp>
        </configuration>
       </plugin>
       <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
     <execution>
      <phase>verify</phase>
      <goals>
       <goal>transform</goal>
      </goals>
     </execution>
    </executions>
    <configuration>
     <transformationSets>
      <transformationSet>
       <dir>${project.build.directory}/jmeter/results</dir>
       <stylesheet>${project.basedir}/src/test/resources/jmeter-results-detail-report_21.xsl</stylesheet>
       <outputDir>${project.build.directory}/jmeter/results</outputDir>
       <fileMappers>
        <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
         <pattern>(.*?)\s(.*?)</pattern>
         <replacement>$1$2</replacement>
         <replaceAll>true</replaceAll>
        </fileMapper>
        <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
         <targetExtension>.html</targetExtension>
        </fileMapper>
       </fileMappers>
      </transformationSet>
     </transformationSets>
    </configuration>
   </plugin>
   <plugin>
      <groupId>ch.fortysix</groupId>
      <artifactId>maven-postman-plugin</artifactId>
      <version>0.1.2</version>
      <executions>
       <execution>
        <id>send a mail</id>
        <phase>install</phase>
        <goals>
         <goal>send-mail</goal>
        </goals>
        <inherited>false</inherited>
        <configuration>
         <from>admin@test.com</from>
         <subject>Load Test Results</subject>
         <failonerror>true</failonerror>
         <mailhost>relay.apple.com</mailhost>
         <htmlMessageFile>${project.build.directory}/jmeter/results/LoadTestPlan.html</htmlMessageFile>
         <receivers>
            <receiver>email@me.com</receiver>
         </receivers>
         <fileSets>
            <fileSet>
                <directory>${project.build.directory}/jmeter/results</directory>
                <includes>
                    <include>LoadTestPlan.html</include>
                </includes>
            </fileSet>
          </fileSets>
         </configuration>
       </execution>
      </executions>
     </plugin>
4

1 に答える 1

5

これを実現する最善の方法は、 を使用することですprofiles。プラグイン構成を含むプロファイルを定義します。このプロファイルはデフォルトでオフになっており (したがって、開発者が実行mvn clean installしてもアクティブ化されません)、Jenkins ジョブ中にのみアクティブ化します。

したがって、たとえば、pom には、次の行に沿ったものがあります。

<project>
    ...
    <profiles>
        <profile>
            <id>ci-environment</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>build.environment</name>
                    <value>jenkins</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.lazerycode.jmeter</groupId>
                        <artifactId>jmeter-maven-plugin</artifactId>
                        <!-- rest of your jmeter configuration goes here -->
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>xml-maven-plugin</artifactId>
                        <!-- rest of your xml-maven configuration goes here -->
                    </plugin>
                    <plugin>
                        <groupId>ch.fortysix</groupId>
                        <artifactId>maven-postman-plugin</artifactId>
                        <!-- rest of your postman configuration goes here -->
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

したがって、デフォルトではこのプロファイルはアクティブではなく、プラグインは実行されません。Jenkins では、次のようにビルドが実行されるように構成します。

mvn clean install -Dbuild.environment=jenkins

プロファイルには があるidため、次のように名前でプロファイルを具体的に使用するように Jenkins を構成することもできます。

mvn clean install -Pci-environment

プロファイルを有効にする方法の詳細については、次の sonatype リソースを参照してください: http://books.sonatype.com/mvnref-book/reference/profiles-sect-activation.html

于 2013-12-10T07:48:56.623 に答える