我在Jenkins中安装了活动选项参数。在这里,我必须从本地存储的文本文件中选择一个值,然后将其显示为用户的多选选项。 例如,我的文本文件可以有一个条目1 - abc,2 - def。用户必须看到两个条目,并且可以选择其中的一个或两个。这个文本文件是手动维护的。我可以有第三项3-ghi,当我触发詹金斯的工作时,我应该看到所有3项。活跃选择参数
任何人都可以请帮我一下吗?
谢谢你在前进, 罗希特
我在Jenkins中安装了活动选项参数。在这里,我必须从本地存储的文本文件中选择一个值,然后将其显示为用户的多选选项。 例如,我的文本文件可以有一个条目1 - abc,2 - def。用户必须看到两个条目,并且可以选择其中的一个或两个。这个文本文件是手动维护的。我可以有第三项3-ghi,当我触发詹金斯的工作时,我应该看到所有3项。活跃选择参数
任何人都可以请帮我一下吗?
谢谢你在前进, 罗希特
您可以使用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
也可以选择“选择型”为多个值。
试试这个:
// 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
欲了解更多信息,请参阅参考文章这里:https://stackoverflow.com/questions/45336944/how-to-get-ordered-defined-or-all-columns-except-or-after-or-before-a-given -COL –
谢谢你伊戈尔。我已添加您提供的代码。但是,当我选择参数构建,理想情况下,我应该看到abc,def,ghi等,但我什么也没看到...... –
@RohitSavanurkar你检查了你的脚本吗?你可以在http://中运行它,看看它是否从文件中返回这些值。 –
不,我仍然没有看到任何东西,当我运行jenkins工作... –