简体   繁体   English

groovy.lang.MissingPropertyException: 没有这样的属性: jenkins for class: groovy.lang.Binding

[英]groovy.lang.MissingPropertyException: No such property: jenkins for class: groovy.lang.Binding

We're upgrading to a newer version of Jenkins (2.60.1) and a groovy script which was working in the previous Jenkins version (1.596/2) no longer works.我们正在升级到较新版本的 Jenkins (2.60.1) 并且在以前的 Jenkins 版本 (1.596/2) 中工作的 groovy 脚本不再有效。

This is a Jenkins build project, which is parameterized and we're using a Groovy script to provide the choices for a Choice Provider (the Choice Provider is set to System Groovy Choice Parameter).这是一个 Jenkins 构建项目,它是参数化的,我们使用 Groovy 脚本为选择提供程序提供选择(选择提供程序设置为系统 Groovy 选择参数)。

We're trying to get access to the Jenkins environment variables and do so like this (this is part of the Groovy script):我们试图访问 Jenkins 环境变量并这样做(这是 Groovy 脚本的一部分):

import hudson.slaves.EnvironmentVariablesNodeProperty
import hudson.EnvVars

EnvironmentVariablesNodeProperty prop = jenkins.getGlobalNodeProperties().get(EnvironmentVariablesNodeProperty.class)
EnvVars env = prop.getEnvVars()

def MY_VAR = env['MY_JENKINS_VAR']

However, I'm getting the following error when running the script:但是,运行脚本时出现以下错误:

Failed to execute script

groovy.lang.MissingPropertyException: No such property: jenkins for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:224)

It seems to me the "jenkins" reference is expected to be a built-in property provided by Jenkins or perhaps Groovy, but I can't find any information on what I need to do to make it accessible from the Groovy script.在我看来,“jenkins”引用应该是 Jenkins 或 Groovy 提供的内置属性,但我找不到任何关于我需要做什么才能从 Groovy 脚本访问它的信息。

Thanks for any help.谢谢你的帮助。

As pointed out by @Jayan in another post, the solution was to do the following正如@Jayan 在另一篇文章中指出的那样,解决方案是执行以下操作

import jenkins.model.*
jenkins = Jenkins.instance

Then I was able to do the rest of my scripting the way it was.然后我就可以按照原样完成我剩下的脚本编写工作。

Please double check that jenkins is not blocking this import.请仔细检查 jenkins 是否没有阻止此导入。 Go to script approvals and check to see if it is blocking it.转到脚本批准并检查它是否阻止它。 If it is click allow.如果是点击允许。

https://jenkins.io/doc/book/managing/script-approval/ https://jenkins.io/doc/book/managing/script-approval/

For me this problem occurred because I had a some invalid character in my Groovy script.对我来说,发生这个问题是因为我的 Groovy 脚本中有一些无效字符。 In our case this was an extra blank line after the closing bracket of the script.在我们的例子中,这是脚本结束括号后的一个额外的空行。

in my case I have used - (Hyphen) in my script name in case of Jenkinsfile Library.就我而言,在 Jenkinsfile 库的情况下,我在脚本名称中使用了- (连字符)。 Got resolved after replacing - (Hyphen) with _ (Underscore)_ (下划线)替换- (连字符)后得到解决

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 詹金斯 Android groovy.lang.MissingPropertyException: 没有这样的属性: 类的 HOME: groovy.lang.Binding - Jenkins Android groovy.lang.MissingPropertyException: No such property: HOME for class: groovy.lang.Binding Jenkins 方法无法获取变量(groovy.lang.MissingPropertyException:没有这样的属性:类的变量:groovy.lang.Binding) - Jenkins method cannot get variable (groovy.lang.MissingPropertyException: No such property: variable for class: groovy.lang.Binding) groovy.lang.MissingPropertyException:没有这样的属性:类的脚本:groovy.lang.Binding - groovy.lang.MissingPropertyException: No such property: script for class: groovy.lang.Binding groovy.lang.MissingPropertyException:没有这样的属性:class 的 sh:groovy.lang.Binding - groovy.lang.MissingPropertyException: No such property: sh for class: groovy.lang.Binding groovy.lang.MissingPropertyException:否此类属性:类groovy.lang.Binding的管道 - groovy.lang.MissingPropertyException: No such property: pipeline for class: groovy.lang.Binding groovy.lang.MissingPropertyException:没有此类属性:类的节点:groovy.lang.Binding - groovy.lang.MissingPropertyException: No such property: node for class: groovy.lang.Binding groovy.lang.MissingPropertyException:无此类属性:类别:groovy.lang.Binding的kubernetes-当变量为空时 - groovy.lang.MissingPropertyException: No such property: kubernetes for class: groovy.lang.Binding - when variable is empty groovy.lang.MissingPropertyException: 没有这样的属性: buildJobArray for class: groovy.lang.Binding - groovy.lang.MissingPropertyException: No such property: buildJobArray for class: groovy.lang.Binding 获取 groovy.lang.MissingPropertyException: No such property: datepart for class: groovy.lang.Binding - Getting groovy.lang.MissingPropertyException: No such property: datepart for class: groovy.lang.Binding 发生异常:groovy.lang.MissingPropertyException:没有这样的属性:类的内容:groovy.lang.Binding - Exception occurred: groovy.lang.MissingPropertyException: No such property: content for class: groovy.lang.Binding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM