Jenkins:如何使用扩展选择参数插件的 'bindings' 字段?

Jenkins: How to use 'bindings' field of Extended Choice Parameters plugin?

我不明白extendedChoice参数的'bindings'字段怎么用,我查了插件的源代码,看到它在groovyShell的上下文中添加了变量,但是我不会了解如何访问此上下文。

我尝试这样设置绑定:

  def bindings = new Binding()
  bindings.setProperty("foo", "foo value")

  return extendedChoice(
      name: 'jsonParameters',
      bindings: bindings.getVariables().toString(),
      type: 'PT_JSON',
      javascript: jsScript,
      groovyScript: groovyScript)

然后在“groovyScript”中,我希望能够访问我的“foo”变量...

更新: 我创建了一个简单的测试,'binding' 是全局的,我可以访问它!为什么不在我的带有插件的 groovyscript 中?

def bindings = new Binding()
bindings.setVariable("foo", "bar")
GroovyShell groovyShell = new GroovyShell();
Script compiledScript = groovyShell.parse("""
  println "foo: " + binding.variables.get("foo")
""");
compiledScript.setBinding(bindings);
compiledScript.run();

// print "foo: bar"

插件版本:0.78

绑定字段格式不是 Map.toString() 格式,而是 'key=value' 格式,其中条目由 '\n' 分隔:

return extendedChoice(
      name: 'jsonParameters',
      bindings: "key1=value2\nkey2=value2",
      type: 'PT_JSON',
      javascript: jsScript,
      groovyScript: groovyScript)

然后,为了使用这些变量,只需在 groovyScript 中调用 getProperty

getProperty("key1")