我有以下groovy cod在Active Choice Parameter中显示一些文件夹名称,如果文件夹中包含“.a7”文件,则显示该文件,如果没有,则应发布错误消息。我的问题是,如果文件夹“a7.nativ”丢失,我的鳕鱼不显示错误信息,并隐含“.a7”文件的路径(/mnt/a7/v5.5/a7.nativ/v5.5 /55.a7)被打断了。有人可以帮帮我吗?这是鳕鱼:
Build=[]
path2 = "/mnt/cc7/v5.5/a7.nativ/v5.5/"
new File(path2).eachFileMatch(~/.*.a7/) {
Build.add(it.getName())
}
if(Build){
return Build
} else {
return ["There is no file to display"]
}
您需要一个额外的步骤来检查是否存在给定路径。否则,您隐式假设给定文件夹始终存在。请考虑以下修改:
def build = []
def path2 = "/mnt/cc7/v5.5/a7.nativ/v5.5/"
def file = new File(path2)
if (!file.exists()) {
return ["There is no file to display"]
}
file.eachFileMatch(~/.*.a7/) {
build.add(it.getName())
}
return build ?: ["There is no file to display"]