在詹金斯的奴隶上执行Groovy脚本 [英] Executing groovy scripts on Jenkins' slaves

查看:77
本文介绍了在詹金斯的奴隶上执行Groovy脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Groovy插件在Jenkins的奴隶上执行一个简单的groovy脚本.我正在使用执行groovy脚本选项,而使用执行系统groovy脚本选项.我还使用了最新版本(2.4.6)插件的自动安装"(从groovy网站安装)选项.但是,工作失败了,我得到了:

I'm trying to execute a simple groovy script on Jenkins' slaves using the Groovy plugin. I'm using the execute groovy script option and not the execute system groovy script option. I'm also using the "install automatically" (install from groovy website) option of the plugin of the latest version(2.4.6) . However, the job fails and I'm getting this:

Building remotely on .... (...) in workspace C:\Jenkins_Slave\workspace\...
Unpacking https://dl.bintray.com/groovy/maven/apache-groovy-binary-2.4.6.zip to C:\Jenkins_Slave\tools\hudson.plugins.groovy.GroovyInstallation\groovy_2_4_6 on ...
[groovy_reset_dead_slave] $ C:\Jenkins_Slave\tools\hudson.plugins.groovy.GroovyInstallation\groovy_2_4_6\bin\groovy.bat C:\Jenkins_Slave\workspace\...\hudson5850644430171226650.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\Jenkins_Slave\workspace\...\hudson5850644430171226650.groovy: 5: unable to resolve class jenkins.model.Jenkins
 @ line 5, column 1.
   import jenkins.model.Jenkins
   ^

1 error

Build step 'Execute Groovy script' marked build as failure
Finished: FAILURE

我该如何克服这个问题并使它正常工作?

How can I overcome this issue and make it work properly?

推荐答案

来自Groovy插件页面:

Groovy脚本与系统Groovy脚本普通的"Groovy脚本"在运行构建的从属服务器上的派生JVM中运行.它与运行"groovy"命令并传入脚本基本相同.系统常规脚本OTOH在Jenkins主服务器的JVM中运行.因此,它将可以访问Jenkins的所有内部对象,因此您可以使用它来更改Jenkins的状态.它类似于Jenkins脚本控制台功能.

当不使用系统Groovy时,您的类路径中没有Jenkins对象.您需要确保可以从正在运行的作业中访问所需的类,并将其传递到执行groovy脚本"步骤的类路径"字段中.

When not using the system Groovy, you do not have Jenkins object in your classpath. You need to make sure the required classes are accessible from the job you are running, and pass them in the "Class path" field of the "execute groovy script" step.

这篇关于在詹金斯的奴隶上执行Groovy脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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