活动选项参数 [英] Active choices parameter

查看:27
本文介绍了活动选项参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Jenkins中安装了活动选择参数。在这里,我必须从本地存储的文本文件中选择一个值,然后将其作为多选选项显示给用户。 例如,我的文本文件可以有一个条目1-abc,2-def。用户必须看到这两个条目,并且可以选择其中一个或两个。此文本文件是手动维护的。我可以有第三个条目3-ghi,当我触发Jenkins作业时,我应该会看到所有3个条目。

有人能帮帮我吗?

提前感谢您, RoHit

推荐答案

尝试此操作:

// 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

这篇关于活动选项参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆