groovy.lang.MissingPropertyException:没有这样的属性:类经理:Script1 [英] groovy.lang.MissingPropertyException: No such property: manager for class: Script1

查看:88
本文介绍了groovy.lang.MissingPropertyException:没有这样的属性:类经理:Script1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Hudson 中调用 Groovy(使用 groovy 插件)来为我们的构建获取一些属性.但我收到此异常:

I am trying to invoke Groovy inside Hudson (using groovy plugin) to get some properties for our build. But I am getting this exception:

groovy.lang.MissingPropertyException:没有这样的属性:类经理:Script1

groovy.lang.MissingPropertyException: No such property: manager for class: Script1

我通过以下行得到了这个:

I get this with the following line:

def buildNUmber = manager.build.number

当我在 Jenkins 中作为内联命令运行以及使用脚本时会发生这种情况:

This happens when I run as an inline command within Jenkins as well as using a script:

我尝试了下面的解决方案,但在声明过程中失败了(第二行):

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

以上使用:Groovy 命令运行.当我运行构建时,它会出错并抱怨该行 - binding.setVariable("manager", manager);

The above is run using: Groovy command. And when I run the build it errors and complains about the line - binding.setVariable("manager", manager);

当我使用 Groovy 脚本文件时,它会抱怨:

When I use the Groovy script file, then it complains about:

 def buildNumber = manager.build.number

两个错误都是:

groovy.lang.MissingPropertyException:没有这样的属性:类经理:Script1

groovy.lang.MissingPropertyException: No such property: manager for class: Script1

尝试了此线程 还有:

我使用的是 Hudson 2.2.1 和 Groovy 2.1.3.可能有什么问题?

I am using Hudson 2.2.1 and Groovy 2.1.3. What could be wrong?

推荐答案

也许我遗漏了您的某些部分代码,但是您在哪里定义管理器?如果这是完整的 Groovy 脚本,那么您正在尝试绑定一个未声明任何内容的变量,因此它失败也就不足为奇了.

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.

只需定义一个您想要的经理,例如:

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.

这篇关于groovy.lang.MissingPropertyException:没有这样的属性:类经理:Script1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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