Jenkins Active Choice React参数:读取文件生成回滚下拉列表失败求助
问题分析与解决
核心问题
当ENV=INT时,你的脚本返回的是字符串类型(例如"\"R1v112\",\"R1v122\",\"R1v123\""),但Jenkins Active Choice React参数要求返回List对象,这就是下拉列表无选项的根本原因。其他分支直接返回List,因此能正常显示。
修正后的脚本
if(ENV == "INT") { def filePath = "C:\\Users\\Lenovo\\OneDrive\\Documents\\Jenkins-Test\\test.txt" def fileContent = readFile file: filePath // 直接返回读取到的行列表,同时过滤空行 return fileContent.readLines().findAll { it.trim() != "" } } else if(ENV == "VAL") { return ["Test", "Hello"] } else { return ["1", "2"] }
额外注意事项
- 确保Jenkins运行的系统用户对目标文件路径
C:\\Users\\Lenovo\\OneDrive\\Documents\\Jenkins-Test\\test.txt拥有读取权限,权限不足也可能导致读取失败但无明显报错。 - 脚本中的
findAll { it.trim() != "" }用于过滤文件中的空行,避免下拉列表出现无效空选项。
内容的提问来源于stack exchange,提问作者Arjun G
相关产品推荐
相关产品推荐

