2013-03-18 73 views
10

我已經配置了一個Jenkins作業來自動發佈我的Maven項目。這是通過使用以下內容完成的:mvn --batch-mode clean release:prepare release:perform 在批處理模式下,發佈版本和開發版本將自動確定。這正是我想要的。Maven版本:批處理模式下的下一個開發版本

問題是我想增加版本的第二個數字而不是第三個。所以當我發佈1.2.0版本時,下一個開發版本必須是1.3.0-SNAPSHOT。不是1.2.1-SNAPSHOT。 添加命令行參數不是一個選項,因爲這迫使我不斷編輯構建作業。

有關如何更改用於確定下一個開發版本的算法的任何建議?

+1

反對使用** 1.2-SNAPSHOT **而不是** 1.2.0-SNAPSHOT **的一些反對意見。 – khmarbaise 2013-03-18 15:12:03

+2

爲什麼不使用jenkins m2 release插件? https://wiki.jenkins-ci.org/display/JENKINS/M2+Release+Plugin – willome 2013-03-18 15:14:21

+0

我們可能想要在未來使用第三位數字來發布bug,但現在只需要2位數就足夠了。我甚至不知道發佈插件。看起來非常有用,但似乎無法解決非默認版本模式中版本增量的問題。它確實有助於選擇正確的版本。 – bergvandenp 2013-03-18 21:53:53

回答

0

正如Khmarbaise所建議的,我也認爲沒有解決您的問題。

是否有任何規則,可以自動告訴你,如果你必須改變第二個或第三個數字?事實上,我不這麼認爲。說這個,你不能要求Maven/Jenkins爲你選擇它,一次是主要版本數字,另一個是次要版本數字。

您必須通過參數對其進行更改,或讓用戶通過Jenkins M2 Release插件進行配置,如willome所建議的。 它只能是一個手動操作。

0

如果您在Jenkins中使用參數化版本,則可以在不編輯作業的情況下使用命令行參數。檢查作業配置頁面中的「此版本是否已參數化」選項。

這不會讓Jenkins完全獨立執行發佈(這很好,我們不希望機器人接受我們的工作!) - 當您從Jenkins內部手動啓動構建時,您會能夠設置你配置的任何參數。

+0

http://www.whyimcray.com/wp-content/uploads/2015/06/humans_jerbs.jpg – 2015-12-16 22:48:17

+1

你和我不同意機器人無產階級;) – 2015-12-16 22:48:47

+1

你可以從我冷冰冰的手中拿出我的發佈版本! – 2015-12-17 00:42:25

0

您可以使用自定義groovy腳本來自動爲maven-release-plugin提供releaseVersion和developmentVersion。然後maven的命令看起來像somwthing:

MVN清潔版本:乾淨的版本:準備發佈:執行-DreleaseVersion = $ {} releaseVersion = -DdevelopmentVersion $ {} developmentVersion

按照以下步驟在this answer和更改Groovy腳本的一部分適合您的使用情況(例如該部分):

def newFixVersion = 0; 
if (hasSnapshotPart) { 
    newMinorRelVersion = minorVersion; 
    newMinorDevVersion = minorVersion + 1; 
} else { 
    //TODO: either throw an exception here or change the newMinorRelVersion newMinorDevVersion appropriately to suite your use-cases: 
     //throw new IllegalArgumentException("The pom at location " + POM_LOCATION + " contains the version " + projectVersion + " which is not a snapshot version (missing " + SNAPSHOT_PART + "). This is a released version and nothing should happen to it!"); 
} 
0

我有同樣的問題,我想解決這個問題,而不運行多個命令或通過手動插入的版本。

這裏是我的Y(或小)增量的解決方案:

我運行Groovy腳本在初始化階段。此腳本創建release.properties。添加到您的項目/在你的pom.xml建立/插件部分:

 <plugin> 
      <groupId>org.codehaus.gmavenplus</groupId> 
      <artifactId>gmavenplus-plugin</artifactId> 
      <version>1.5</version> 
      <dependencies> 
       <dependency> 
        <groupId>org.codehaus.groovy</groupId> 
        <artifactId>groovy-all</artifactId> 
        <version>2.4.6</version> 
       </dependency> 
      </dependencies> 
      <executions> 
       <!-- Force maven-release-plugin to increase MINOR, not PATCH, and create tag as vX.Y.Z --> 
       <execution> 
        <id>release-parameters</id> 
        <phase>initialize</phase> 
        <goals> 
         <goal>execute</goal> 
        </goals> 
        <configuration> 
         <scripts> 
          <script> 
           <![CDATA[ 
            final String SNAPSHOT = '-SNAPSHOT' 

            Properties releaseProps = new Properties() 
            File releasePropsFile = new File('release.properties') 
            String releaseVersion = '${project.version}'.replace('-SNAPSHOT', '') 
            String[] vNumbers = releaseVersion.split('\\.') 
            String snapshotVersion = vNumbers[0] + '.' + (Integer.parseInt(vNumbers[1]) + 1) + '.' + '0' + SNAPSHOT 

            releaseProps.setProperty('scm.tag', 'v' + releaseVersion) 
            releaseProps.setProperty('project.rel.${project.groupId}:${project.artifactId}', releaseVersion) 
            releaseProps.setProperty('project.dev.${project.groupId}:${project.artifactId}', snapshotVersion) 
            releaseProps.store(releasePropsFile.newWriter(), null) 
           ]]> 
          </script> 
         </scripts> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

這個腳本vX.Y.Z也改變了標籤在你的供應鏈管理。初始化階段未執行發行版:準備階段。要解決此問題,您可以運行一個發佈前「MVN安裝」,或更改您發佈命令:

mvn --batch-mode initialize clean release:prepare release:perform 

關於release.properties:https://maven.apache.org/maven-release/maven-release-plugin/examples/non-interactive-release.html

1

我知道這是一個有點老的文章,但我沒有在網上找到我真正喜歡的答案,並且我能夠想出一些可能適合其他人的答案...

我希望增加minorVersion,因爲OP的狀態是,我能夠通過在我的項目POM中使用構建幫助器插件(解析版本)和發佈插件的組合來實現。請注意POM中引用的「初始化」階段和maven運行屬性...

下面是POM的摘錄,我們使用構建助手插件來解析我們可以在發佈插件中引用的版本...

<plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>build-helper-maven-plugin</artifactId> 
       <version>${maven.build.helper.plugin.version}</version> 
       <executions> 
        <execution> 
         <id>parse-versions-for-release</id> 
         <phase>initialize</phase> 
         <goals> 
          <goal>parse-version</goal> 
         </goals> 
         <configuration> 
          <propertyPrefix>parsedVersion</propertyPrefix> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-release-plugin</artifactId> 
       <version>${maven.release.plugin.version}</version> 
       <configuration> 
        <autoVersionSubmodules>true</autoVersionSubmodules> 
        <tagNameFormat>@{project.artifactId}[email protected]{project.version}</tagNameFormat> 
        <useReleaseProfile>false</useReleaseProfile> 
        <developmentVersion>${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0-SNAPSHOT</developmentVersion> 
       </configuration> 
      </plugin> 

現在我們可以只運行一個漂亮的正常釋放,但將在「初始化」階段,觸發版本解析(並確保之前尋找解析版本中,它發生)......

mvn initialize release:clean release:prepare release:perform