【问题标题】:Jenkins - MavenBuild.getMavenArtifacts() Returns NullJenkins - MavenBuild.getMavenArtifacts() 返回 Null
【发布时间】:2012-04-17 16:17:59
【问题描述】:

自 Jenkins 1.460 起,在 MavenBuild 的实例上调用 getMavenArtifacts() 将返回 null,而以前可以正常工作。

Jenkins API 中是否有重大更改,或者这是 Jenkins 错误?

我正在执行的代码是构建后的 System Groovy 脚本,它将构建的 Maven 版本公开为环境变量,供 Jenkins 构建过程中的后续步骤使用:

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

【问题讨论】:

  • 1.460 肯定有changes to Maven Plugin。如果无法将 Jenkins 回滚到以前的版本,请考虑仅将插件固定到以前的版本。

标签: maven groovy hudson jenkins


【解决方案1】:

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

替补:

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

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

【讨论】:

  • 嘿,我遇到了异常,我在 jenkins 1.625.3.2 => 错误:构建步骤失败,异常 groovy.lang.MissingMethodException:没有方法签名:hudson.model.FreeStyleProject .getModules() 适用于参数类型:() 值:[] 可能的解决方案:getModuleRoot()、getModuleRoots()、getBuilds()、getWidgets()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-21
  • 2020-06-19
  • 2011-10-15
相关资源
最近更新 更多