Jenkins - MavenBuild.getMavenArtifacts () Returns Null

Since Jenkins 1.460, calling getMavenArtifacts() on the MavenBuild instance returns null, whereas earlier this would work fine.

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

The code I execute is a Groovy script post-build system that provides the Maven version of the build as an environment variable for the next steps in the Jenkins build process:

 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 hudson jenkins groovy
Apr 17 '12 at 16:17
source share
1 answer

I found a workaround, although I don’t know why an unexplained violation was made in the API - I hope this is a bug that will be fixed.

Replacement:

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

for

 def mavenVer = currentBuild.getParent().getModules().toArray()[0].getVersion(); 
+1
Apr 18 2018-12-12T00:
source share
β€” -



All Articles