2013-12-10 2 views
2

JMeter 성능 테스트 계획을 조건부로 실행하는 방법을 알아 내려고하고 있습니다. 내 Jenkins CI 작업을 실행하고 싶지만 개발자가 실행하면 mvn clean install 아래 플러그인을 실행하지 않으려 고합니다. 조건부로 아래 플러그인을 실행하기 위해 pom.xml을 어떻게 수정할 수 있습니까?조건부 실행 JMeter 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>[email protected]</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 protected]</receiver> 
     </receivers> 
     <fileSets> 
      <fileSet> 
       <directory>${project.build.directory}/jmeter/results</directory> 
       <includes> 
        <include>LoadTestPlan.html</include> 
       </includes> 
      </fileSet> 
      </fileSets> 
     </configuration> 
     </execution> 
     </executions> 
    </plugin> 

답변

5

가장 좋은 방법은 profiles 함께. 플러그인 구성을 포함하는 프로파일을 정의합니다. 이 프로필은 기본적으로 해제되어 있으므로 (개발자가 mvn clean install을 실행하면 활성화되지 않습니다), Jenkins 작업 중에 만 활성화 할 수 있습니다.

그래서 치어의 예를 들어, 당신은이 라인을 따라 뭔가 것 :

<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> 

그래서 기본적으로이 프로필이 활성화되지 않은, 그리고 플러그인 못해 실행합니다. 프로파일이 id을 가지고

mvn clean install -Dbuild.environment=jenkins

으로 다음과 같이 당신은 또한 특별히 이름으로 프로필을 사용하여 젠킨스를 구성 할 수 있습니다 : 다음과 같이 젠킨스에 당신이 실행하는 빌드를 구성합니다

mvn clean install -Pci-environment

프로필을 활성화하는 방법에 대한 자세한 내용은 다음 소니아 형식 리소스를 참조하십시오. http://books.sonatype.com/mvnref-book/reference/profiles-sect-activation.html

+1

훌륭한 답변, 많은 감사합니다! – c12

+0

도움을 청하게되어 기쁩니다. – DB5

관련 문제