[英]groovy.lang.MissingPropertyException: No such property: manager for class: Script1
I am trying to invoke Groovy inside Hudson (using groovy plugin) to get some properties for our build.我正在尝试在 Hudson 中调用 Groovy(使用 groovy 插件)来为我们的构建获取一些属性。 But I am getting this exception:但我收到此异常:
groovy.lang.MissingPropertyException: No such property: manager for class: Script1 groovy.lang.MissingPropertyException:没有这样的属性:类经理:Script1
I get this with the following line:我通过以下行得到了这个:
def buildNUmber = manager.build.number
This happens when I run as an inline command within Jenkins as well as using a script:当我在 Jenkins 中作为内联命令运行以及使用脚本时会发生这种情况:
I tried the solution below, but it fails during the declaration itself (line two):我尝试了下面的解决方案,但在声明过程中失败了(第二行):
Binding binding = new Binding();
binding.setVariable("manager", manager);
GroovyShell shell = new GroovyShell(binding);
shell.evaluate(new File("d:/dev/others/hudson/userContent/ScriptStuff.groovy").text);
The above is run using: Groovy command.以上是使用:Groovy 命令运行的。 And when I run the build it errors and complains about the line - binding.setVariable("manager", manager);
当我运行构建时,它会出错并抱怨该行 - binding.setVariable("manager", manager);
When I use the Groovy script file, then it complains about:当我使用 Groovy 脚本文件时,它会抱怨:
def buildNumber = manager.build.number
Both errors are :这两个错误是:
groovy.lang.MissingPropertyException: No such property: manager for class: Script1 groovy.lang.MissingPropertyException:没有这样的属性:类经理:Script1
Tried everything mentioned in this thread as well:也尝试了此线程中提到的所有内容:
I am using Hudson 2.2.1 and Groovy 2.1.3.我正在使用 Hudson 2.2.1 和 Groovy 2.1.3。 What could be wrong?可能有什么问题?
manager
is provided by certain Groovy script plugins, but not all. manager
由某些 Groovy 脚本插件提供,但不是全部。 To make your script generic, use the Jenkins/Hudson API instead:要使您的脚本通用,请改用 Jenkins/Hudson API:
import hudson.model.*
def build = Thread.currentThread().executable
def buildNumber = build.number
...
Just in case it helps, if you are using the 'Execute System Groovy Script', you don't need to use the 'manager' variable.以防万一,如果您使用的是“执行系统 Groovy 脚本”,则不需要使用“管理器”变量。 This worked for me -这对我有用-
def workspace = build.getEnvVars()["WORKSPACE"]
groovy.lang.MissingPropertyException:的原因之一是在您使用其范围之外的变量或尚未定义该变量时抛出。
Maybe I'm missing some part of your code, but where do you define the manager?也许我遗漏了您的代码的某些部分,但是您在哪里定义经理? If that's the complete Groovy script, you're trying to bind a variable which isn't declared anything, so it isn't surprising that it fails.如果这是完整的 Groovy 脚本,那么您正在尝试绑定一个未声明任何内容的变量,因此它失败也就不足为奇了。
Just define a manager it that's what you want, like:只需定义一个您想要的经理,例如:
def manager = "my manager" // probably not what you want
This should solve your current error.这应该可以解决您当前的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.