问题描述
我们正在升级到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脚本为Choice Provider提供选择(将Choice Provider设置为System Groovy Choice Parameter).
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:没有此类属性:类的詹金斯:groovy.lang.Binding的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!