Jenkins Packages on Groovy Classpath?

做~自己de王妃 提交于 2020-01-13 10:23:12

问题


When using the Groovy Jenkins plugin (not the Groovy Post Build Plugin, which is a different thing) as a Post Step, I can't resolve classes in the hudson.model package.

Do I need to add the Jenkins .war onto the classpath, or should these packages already be there?

Script:

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

Output:

[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;
[...]

回答1:


Yes, if it's a Groovy Script you do need to add the jenkins-core jar to your classpath, and the stapler jar too.

If it's a Groovy System Script then it is run inside the master's JVM, meaning all the Jenkins classes and dependencies are already on the classpath.



来源:https://stackoverflow.com/questions/9996315/jenkins-packages-on-groovy-classpath

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