简体   繁体   English

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

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

相关问题 没有此类属性:清洁类groovy.lang.Binding - No such property: clean for class groovy.lang.Binding shell或groovy脚本在maven编译期间创建Java类 - shell or groovy script to create Java class during maven compile gmaven插件:如何在pom.xml中为外部groovy脚本设置属性 - gmaven plugin: how to set property in pom.xml for external groovy script 如何使用通过gmavenplus运行的Groovy脚本设置Maven项目属性? - How do I set a maven project property with a groovy script run with gmavenplus? groovy-maven-plugin:2.0:execute失败:无此类属性:class:java.io.File的canonicalFile - groovy-maven-plugin:2.0:execute failed: No such property: canonicalFile for class: java.io.File Web脚本库-Alfresco - Web script groovy - Alfresco 加载插件管理器时出错:无法创建类[org.codehaus.groovy.grails.plugins.web.mapping.UrlMappingsGrailsPlugin]的新实例 - Error loading plugin manager: Could not create a new instance of class [org.codehaus.groovy.grails.plugins.web.mapping.UrlMappingsGrailsPlugin] 在流程资源阶段(常规脚本)无法从Maven依赖项加载驱动程序类 - Cannot load driver class from maven dependency during process-resource phase (groovy script) Groovy编译以`java.lang.StackOverflowError`结尾 - Groovy compilation ends with `java.lang.StackOverflowError` “java.lang.NoClassDefFoundError:无法初始化 class org.codehaus.groovy.vmplugin.v7.Java7”错误当我尝试运行放心测试 ZA2F2ED4F8EBC2CBB4C21A29DC4 - “java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7” error when I try to run a rest-assured test class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM