Groovy Classpath上的Jenkins包?

当使用Groovy Jenkins插件(不是Groovy Post Build Plugin,这是一个不同的东西)作为Post Step时,我无法解析hudson.model包中的类。

我是否需要将Jenkins .war添加到类路径中,或者这些包是否已经存在?

脚本:

 import hudson.model.*; import hudson.util.*; AbstractBuild currentBuild = (AbstractBuild) Thread.currentThread().executable; def mavenVer = currentBuild.getMavenArtifacts().getModuleRecords()[0].mainArtifact.version; println mavenVer; ParametersAction newParamAction = new hudson.model.ParametersAction(new hudson.model.StringParameterValue(“MAVEN_VERSION”, mavenVer)); currentBuild.addAction(newParamAction); 

输出:

 [Common] $ /home/tester/tools/Groovy_1.8.3/bin/groovy /home/tester/workspace/Common/hudson8369102960709507246.groovy org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /home/tester/workspace/Common/hudson8369102960709507246.groovy: 8: unable to resolve class AbstractBuild @ line 8, column 15. AbstractBuild currentBuild = (AbstractBuild) Thread.currentThread().executable; [...] 

是的,如果它是一个Groovy Script你需要将jenkins-core jar添加到你的类路径,以及订书机jar。

如果它是一个Groovy System Script那么它在master的JVM中运行,这意味着所有Jenkins类和依赖项都已经在类路径中。