Jenkins主动选择React参考参数Groovy脚本从文件获取数组内容

问题描述 投票:0回答:1

我正在尝试从文件中显示 Jenkins 中的回滚参数列表(其中文件每行都有回滚编号)我正在读取该内容并将其存储为数组,并在代码块中返回该数组,但参数没有下拉值。

我没有收到任何错误 - 不确定我在这里做错了什么。

if(ENV == "INT") {
def filePath = "C:\\\\Users\\\\Lenovo\\\\OneDrive\\\\Documents\\\\Jenkins-Test\\\\test.txt"
                def fileContent = readFile file: filePath
                def modifiedList = fileContent.readLines()
               def values = modifiedList.collect { "\"${it}\"" }.join(',')
                return values
}
else if(ENV == "VAL") {
return ["Test", "Hello"]
}
else {
return ["1", "2"]
}

ENV 是之前的参数,我在这里将其用作引用参数。

任何人都可以建议解决方案吗!

我期待以下:

Test.txt(文件内容不是静态的,每个值都将换行)有文件内容:

R1v112
R1v122
R1v123

我想显示如果选择的 ENV 为 INT,则回滚下拉列表应显示值 R1v112, R1v122, R1v123可供选择。

jenkins groovy jenkins-pipeline jenkins-plugins
1个回答
0
投票

您不是在这里编写脚本化管道,它是纯 Groovy 脚本,因此未定义像

readFile
这样的 Jenkins 步骤。 Active Choices 的错误报告很糟糕,你必须求助于这样的黑客来看看到底是什么失败了

try {
... your code
} catch(e) {
    return [e.toString()]
}
© www.soinside.com 2019 - 2024. All rights reserved.