我的Jenkins中安装了有效的选择参数。在这里,我必须从本地存储的文本文件中选择一个值,然后将其显示为用户的多选选项。 例如,我的文本文件可以有一个条目1 - abc,2 - def。用户必须查看这两个条目,并且可以选择它们中的任何一个或两个。此文本文件是手动维护的。我可以有第三个条目3-ghi,当我触发Jenkins工作时,我应该看到所有3个条目。
有人可以帮助我吗?
提前谢谢你, 罗希特夏尔
答案 0 :(得分:0)
您可以使用groovy脚本来解析文件和返回选项,例如:
def list = []
File textfile= new File("path-to-file")
textfile.eachline { line ->
//assuming you want only text values without a number
list.add(line.split('-')[1]) }
return list
同时选择"选择类型"多个值。
答案 1 :(得分:0)
试试这个:
// create blank array/list to hold choice options for this parameter and also define any other variables.
def list = []
def file = "/opt/data/jenkins/jobs/dummy_dummy/workspace/somefile.txt"
// create a file handle named as textfile
File textfile= new File(file)
// now read each line from the file (using the file handle we created above)
textfile.eachLine { line ->
//add the entry to a list variable which we'll return at the end.
//The following will take care of any values which will have
//multiple '-' characters in the VALUE part
list.add(line.split('-')[1..-1].join(',').replaceAll(',','-'))
}
//Just fyi - return will work here, print/println will not work inside active choice groovy script / scriptler script for giving mychoice parameter the available options.
return list