Jenkins - MavenBuild.getMavenArtifacts() Returns Null

可紊 提交于 2019-12-06 15:38:13

问题


Since Jenkins 1.460, calling getMavenArtifacts() on an instance of MavenBuild is returning null, whereas previously that would work fine.

Have there been breaking changes in the Jenkins API, or is this a Jenkins bug?

The code I'm executing is a post-build System Groovy script, that exposes the Maven version of a build as an environment variable for subsequent steps in the Jenkins build process to use:

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:


I found a workaround, although I don't know why an unannounced breaking change was made to the API - hopefully it's a bug that will get fixed.

Substitute:

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

for

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


来源:https://stackoverflow.com/questions/10195057/jenkins-mavenbuild-getmavenartifacts-returns-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!