Jenkins 管道函数 fileExist 可以处理通配符吗?

Can Jenkins pipeline function fileExist handle wildcards?

Jenkins 管道函数 fileExist 可以处理通配符吗? 我在工作区文件夹中有一个 zip 文件。以下代码给出 hifalse:

WORKSPACE = pwd()
echo "hi"+fileExists("${WORKSPACE}/*.zip*")

但是我该怎么做呢?

fileExists step 既不接受通配符,也不接受绝对路径。

但是,如果您安装可选的 Pipeline Utility Steps plugin, you can make use of the findFiles step,它会接受通配符。例如:

def files = findFiles glob: '**/*.zip'
boolean exists = files.length > 0

作为替代方案,如果没有该插件,您可以使用 shell 步骤 运行 find:

def exitCode = sh script: 'find -name "*.zip" | egrep .', returnStatus: true
boolean exists = exitCode == 0