为建设一个单一的詹金斯的工作多Maven的配置文件 [英] Building multiple Maven profiles for a single Jenkins job

查看:126
本文介绍了为建设一个单一的詹金斯的工作多Maven的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个单一的詹金斯的工作多Maven的配置文件。每个配置文件更改某些code,然后通过执行 MVN -Pdev安装然后 MVN -Pprod安装创建一个罐子在命令行(使用根据Maven的 MVN -Pdev,督促安装应该工作,但它不工作对我来说)。这里有两个配置文件我的项目的的pom.xml

I am trying to build multiple Maven profiles in a single Jenkins job. Each profile changes some code and then creates a jar by executing mvn -Pdev install then mvn -Pprod install in the command line (According to Maven using mvn -Pdev,prod install is supposed to work but it isn't working for me). Here are the two profiles in my project's pom.xml:

<profiles>   
 <!-- prod profile -->
   <profile>
    <id>prod</id>
     <build>
      <plugins> 

          <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.2</version>

                <executions>
                    <execution>                    
                        <phase>process-resources</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>

                         <file>src/main/java/com/IQzone/android/configuration/AbstractHoldingRefreshable.java</file>
                    <replacements>
                        <replacement>
                            <token>TrUe</token>
                            <value>TOAST_SWITCH</value>
                        </replacement>
                    </replacements>

                </configuration>

            </plugin>

         <plugin>
           <artifactId>maven-jar-plugin</artifactId>
           <executions>
             <execution>
               <phase>package</phase>
               <goals>
                 <goal>jar</goal>
               </goals>
               <configuration>
                 <classifier>prod</classifier>
               </configuration>
             </execution>
           </executions>
         </plugin>
       </plugins>
     </build>
   </profile>


 <!-- dev profile -->
   <profile>
     <id>dev</id>
     <build>
        <plugins>

            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.2</version>

                <executions>
                    <execution>                    
                        <phase>process-resources</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>

                    <file>src/main/java/com/IQzone/android/configuration/AbstractHoldingRefreshable.java</file>
                    <replacements>
                        <replacement>
                            <token>TOAST_SWITCH</token>
                            <value>TrUe</value>
                        </replacement>
                    </replacements>

                </configuration>

            </plugin>

            <!-- build project with JAVA 1.6 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>


         <plugin>
           <artifactId>maven-surefire-plugin</artifactId>
           <configuration>
             <skip>true</skip>
           </configuration>
         </plugin>
         <plugin>
           <artifactId>maven-jar-plugin</artifactId>
           <executions>
             <execution>
               <phase>package</phase>
               <goals>
                 <goal>jar</goal>
               </goals>
               <configuration>
                 <classifier>dev</classifier>
               </configuration>
             </execution>
           </executions>
         </plugin>



       </plugins>
     </build>
   </profile>
 </profiles>

我将如何设置詹金斯自动每当作业被打了建立一个单一的詹金斯工作建立这两个配置文件?并提出这两个罐子在Artifactory的?我很少詹金斯知识上没有这么多的信息在网络上。

How would I setup Jenkins to automatically build both of these profiles for a single Jenkins job whenever the job is hit for a build? And put both of these jars in the Artifactory? I have very little Jenkins knowledge and there isn't much information on this on the web.

推荐答案

您可以创建一个詹金斯矩阵的工作。矩阵的工作让同样的工作与不断变化的设置(在您的情况:一个字符串)运行。

You could create a Jenkins matrix job. A matrix job allows the same job to run with changing settings (in your case: a string).

每个改变设置称为轴。在你的情况,你会创建一个包含两个值的字符串轴:开发和督促

Each changing setting is called an axis. In your case you would create a string axis containing the two values: dev and prod.

这样,你的工作将运行两次,与这两个值。

That way your job would run twice, with both values.

不过:您的配置文件的使用是危险的。由于用来运行生成的配置文件没有编入你的神器,你打破了一个来源的修订,应该总是导致完全相同的目标神器的Maven(见合同:<一href=\"http://www.blackbuild.com/how-to-really-use-maven-profiles-without-endangering-your-karma/\">http://www.blackbuild.com/how-to-really-use-maven-profiles-without-endangering-your-karma/为更详细的解释)

However: your usage of profiles is dangerous. Since the profile used to run the build is not codified into your artifact, your break the "one source revision should always lead to exactly the same target artifact" contract of Maven (see: http://www.blackbuild.com/how-to-really-use-maven-profiles-without-endangering-your-karma/ for a more detailed explanation)

考虑创建使用分类器(-dev和-prod)无论是两个不同的文物,甚至更好:创建构建两个独立的模块,每个人只创造你的目标工件之一

Consider creating either two different artifacts using classifier (-dev and -prod) or even better: create two separate modules of your build, each one creating only one of your target artifacts.

这篇关于为建设一个单一的詹金斯的工作多Maven的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆