如何在ExtendedChoice Jenkins插件中使用Groovy变量?
我想使用Groovy变量作为ExtendedChoice插件的值。看似微不足道,但不起作用-失败于“groovy.lang.MissingPropertyException:无此类属性:$COMPONENTS\u类列表:groovy.lang.Binding” 有什么想法吗如何在ExtendedChoice Jenkins插件中使用Groovy变量?,jenkins,groovy,compilation,closures,jenkins-pipeline,Jenkins,Groovy,Compilation,Closures,Jenkins Pipeline,我想使用Groovy变量作为ExtendedChoice插件的值。看似微不足道,但不起作用-失败于“groovy.lang.MissingPropertyException:无此类属性:$COMPONENTS\u类列表:groovy.lang.Binding” 有什么想法吗 environment { COMPONENTS_LIST= "one two three" } parameters { extendedChoice (description: 'Components',
environment {
COMPONENTS_LIST= "one two three"
}
parameters {
extendedChoice (description: 'Components', multiSelectDelimiter: ' ',
name: 'Components_To_Deploy', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_SELECT',
value: $COMPONENTS_LIST, visibleItemCount: 3)
}
这是一个语法错误,您试图将命名参数
值设置为变量$COMPONENTS\u LIST
的内容;这是不存在的。变量的范围也有问题;需要在两个闭包中都提供。因此,请尝试使用所需的值在两个闭包的范围外定义一个变量,然后在闭包内使用这些变量,如下例所示:
def componentsList = "one two three"
environment {
COMPONENTS_LIST = componentsList
}
parameters {
extendedChoice (description: 'Components', multiSelectDelimiter: ' ',
name: 'Components_To_Deploy', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_SELECT',
value: componentsList, visibleItemCount: 3)
}
我认为这是一个语法问题。必须使用双引号引用变量:
def COMPONENTS_LIST= "one two three"
parameters {
extendedChoice (description: 'Components', multiSelectDelimiter: ' ',
name: 'Components_To_Deploy', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_SELECT',
value: "${COMPONENTS_LIST}", visibleItemCount: 3)
}
不幸的是,这些方法都失败了,只有一个例外。我只是额外考虑更新了答案,我的原始答案没有考虑变量的范围,只是使用中的语法错误。Marco,谢谢!知道了。不幸的是,同样的事情似乎在声明性管道中是可以撤销的,但至少我理解这个想法。你可以简单地使用:没有引号和美元符号。