Can Jenkins pipeline function fileExist handle wildcards?
I do have a zip file in the workspace folder. Following code gives hifalse
:
WORKSPACE = pwd()
echo "hi"+fileExists("${WORKSPACE}/*.zip*")
but then how can I do it?
The fileExists
step accepts neither wildcards, nor absolute paths.
However, if you install the optional Pipeline Utility Steps plugin, you can make use of the findFiles
step, which does accept wildcards. For example:
def files = findFiles glob: '**/*.zip'
boolean exists = files.length > 0
As an alternative, without that plugin, you could use a shell step to run find
:
def exitCode = sh script: 'find -name "*.zip" | egrep .', returnStatus: true
boolean exists = exitCode == 0