Jenkins maven拆分版本范围

时间:2017-06-16 09:06:18

标签: maven jenkins jenkins-plugins jenkins-pipeline

问题

Maven解释:

versions:update-parent -N -DallowSnapshots=true -DparentVersion=[1.8.0,1.9.0) 

为:

versions:update-parent -N -DallowSnapshots=true '-DparentVersion=[1.8.0' '1.9.0)'

我试图在Jenkinsfile管道中运行Maven就像这样(添加换行符以提高可读性,这一切都在一行上):

sh "mvn release:clean release:prepare -X 
-DcheckModificationExcludeList=pom.xml,pom.xml.versionsBackup 
-Dresume=false 
-DpreparationGoals=\'clean install -Dmaven.test.failure.ignore=true' 
-Darguments=\'-Dbuild.phase.beforeDeploy -DskipTests=true\' 
-DcompletionGoals=\'versions:update-parent -N -DallowSnapshots=true -DparentVersion=[1.8.0,1.9.0)\' 
-DtagNameFormat=@{project.groupId}-@{project.artifactId}-@{project.version}"

当Maven开始执行完成目标部分时,它会拆分版本范围,将其视为2个单独的参数并退出并显示错误。相关日志片段:

[INFO] Executing goals 'versions:update-parent -N -DallowSnapshots=true -DparentVersion=[1.8.0,1.9.0)'...
[DEBUG] Using ${maven.home} of: '/home/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn-3.2.5'.
[DEBUG] Executing: /bin/sh -c cd /home/jenkins/workspace/ife-jen-maven-runner_master-6CIUKZ3STQA5HR4E2RYGZ5GBNFZPFT7UYLMWJ5EMFIBJ6ATW7RUA/appdir && /home/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn-3.2.5/bin/mvn -X -D maven.repo.local=/home/jenkins/.m2/repository -s /tmp/release-settings1714400534004224741.xml -D skipTests=true -D build.phase.beforeDeploy=true -P nexus versions:update-parent -N -DallowSnapshots=true '-DparentVersion=[1.8.0' '1.9.0)'

[INFO] [DEBUG] === REACTOR BUILD PLAN ================================================
[INFO] [DEBUG] Project: my-project:pom:6.4.123-SNAPSHOT
[INFO] [DEBUG] Tasks:   [versions:update-parent, 1.9.0)]

INFO] [ERROR] Unknown lifecycle phase "1.9.0)". You must specify a valid lifecycle phase...

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project grin-colis: Maven execution failed, exit code: '1' -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project grin-colis: Maven execution failed, exit code: '1'
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)

你遇到过类似的问题吗?你是怎么处理它的?

设置

构建在Linux Docker slave上运行(容器不由Jenkins管理)。

版本

  • Jenkins 2.46.1
  • Pipeline 2.5
  • Maven Integration插件2.16
  • Container JDK OpenJDK 1.8.0_121
  • Job JDK Oracle JDK 6u45(项目需要java 6,使用自动安装选项并在Jenkinsfile工具部分声明)
  • Maven 3.2.5
  • Maven版本插件2.4(在pom中声明)

2 个答案:

答案 0 :(得分:0)

您可能希望将参数放入(转义)引号:

sh "mvn release:clean release:prepare -X 
-DcheckModificationExcludeList=pom.xml,pom.xml.versionsBackup 
-Dresume=false 
-DpreparationGoals=\'clean install -Dmaven.test.failure.ignore=true' 
-Darguments=\'-Dbuild.phase.beforeDeploy -DskipTests=true\' 
-DcompletionGoals=\'versions:update-parent -N -DallowSnapshots=true -DparentVersion=\"[1.8.0,1.9.0)\"\' 
-DtagNameFormat=@{project.groupId}-@{project.artifactId}-@{project.version}"

答案 1 :(得分:0)

事实证明,罪魁祸首是maven-release-plugin的最新版本(2.5.3)。我还没有测试过新版本(2.3.x,2.4.x)是否可行。

在项目中运行此配置有助于:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.2.2</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.scm</groupId>
            <artifactId>maven-scm-provider-gitexe</artifactId>
            <version>1.9.5</version>
        </dependency>
    </dependencies>
</plugin>