groovy.lang.MissingPropertyException: 没有这样的属性: jenkins for class: groovy.lang.Binding [英] groovy.lang.MissingPropertyException: No such property: jenkins for class: groovy.lang.Binding

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

问题描述

我们正在升级到较新版本的 Jenkins (2.60.1),并且在之前的 Jenkins 版本 (1.596/2) 中运行的 groovy 脚本不再有效.

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 构建项目,它是参数化的,我们使用 Groovy 脚本为选择提供程序提供选择(选择提供程序设置为系统 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 脚本的一部分):

We're trying to get access to the Jenkins environment variables and do so like this (this is part of the Groovy script):

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)

在我看来,jenkins"引用应该是 Jenkins 或 Groovy 提供的内置属性,但我找不到任何关于我需要做什么才能从 Groovy 脚本访问它的信息.

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.

感谢您的帮助.

推荐答案

正如@Jayan 在另一篇文章中所指出的,解决方案是执行以下操作

As pointed out by @Jayan in another post, the solution was to do the following

import jenkins.model.*
jenkins = Jenkins.instance

然后我就可以照原样完成我剩下的脚本编写工作了.

Then I was able to do the rest of my scripting the way it was.

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

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