2012-04-17 30 views
0

由于Jenkins 1.460,在MavenBuild的实例上调用getMavenArtifacts()正在返回null,而之前的工作正常。Jenkins - MavenBuild.getMavenArtifacts()返回NULL

Jenkins API中是否发生过突变,或者这是一个Jenkins错误?

我执行的代码生成后,系统Groovy脚本,暴露构建的Maven的版本,如在詹金斯后续步骤的环境变量构建过程中使用:

import hudson.model.*; 
import hudson.util.*; 

def thr = Thread.currentThread(); 
def currentBuild = thr?.executable; 
def mavenVer = currentBuild.getMavenArtifacts().getModuleRecords()[0].mainArtifact.version; 
def newParamAction = new hudson.model.ParametersAction(new hudson.model.StringParameterValue("MAVEN_VERSION", mavenVer)); 
currentBuild.addAction(newParamAction); 
+0

肯定有过[更改Maven插件(https://github.com/jenkinsci/jenkins/commits/jenkins-1.460/maven - 插件)为1.460。如果将Jenkins滚回到以前的版本不是一种选择,请考虑将插件固定到以前的版本。 – 2012-04-18 08:13:30

回答

1

我找到了一种解决方法,尽管我不知道为什么要对API进行未经宣布的重大更改 - 希望这是一个可以修复的错误。

替补:

def mavenVer = currentBuild.getMavenArtifacts().getModuleRecords()[0].mainArtifact.version; 

def mavenVer = currentBuild.getParent().getModules().toArray()[0].getVersion(); 
+0

嘿我得到这个异常,我在詹金斯1.625.3.2 =>错误:生成步骤失败,例外 groovy.lang.MissingMethodException:没有方法的签名:hudson.model.FreeStyleProject.getModules()适用参数类型:()values:[] 可能的解决方案:getModuleRoot(),getModuleRoots(),getBuilds(),getWidgets() – Max 2016-03-09 18:17:56