如何在Jenkins Pipeline中将String转换为ArryList



Jenkins extendedChoice参数允许用户同时选择多项选项。例如

'''Jenkins scripted pipeline--head extendedChoice params 
properties ([
parameters([
extendedChoice(name: 'office_components',
defaultValue: 'outlook',
description: 'Muti choice, please select office components',
value: 'word,excel,ppt,outlook',
type: 'PT_CHECKBOX')
])
])
'''

我们可以使用"${office_components}"来获取Groovy管道中的值。在这里,我们假设用户选择了"word,excel,outlook",我使用:

'''Jenkins pipeline--body
def selected="${office_components}" 
println selected  //word,excel,outlook 
println selected.getClass() // class org.codehaus.groovy.runtime.GStringImpl
'''    

总之,如何将上面的"word,excel,outlook"转换为["word","excel","outlook"]

只需像在Java中一样使用split(",")即可。

因此,以下内容应该为您完成任务。

listSelected = selected.toString().split(",")
println( listSelected.collect{""" + it + """} )

最新更新