Jenkins Groovy类路径上的软件包? [英] Jenkins Packages on Groovy Classpath?

查看:665
本文介绍了Jenkins Groovy类路径上的软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Groovy Jenkins插件(不是Groovy Post Build Plugin,这是另一回事)作为Post Step时,我无法解析 hudson.model package。

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.

我需要将Jenkins .war添加到类路径中,还是应该已经在那里?

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

脚本:

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


推荐答案

如果它是 Groovy脚本您需要将 jenkins-core jar添加到您的classpath和订书机jar。

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

如果它是一个 Groovy系统脚本,它会在主JVM ,这意味着所有Jenkins类和依赖关系已经在类路径中。

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.

这篇关于Jenkins Groovy类路径上的软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆