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?
Jenkins allows wildcards in URLs so that we can filter artifacts like this: http://myjenkins.local/job/MyJob/lastSuccessfulBuild/artifact/**/*-release.apk/*zip*/foo.zip. If the filter results in multiple files, this is great-- you get all the artifacts downloaded in a single zip file.
cleanWs : Delete workspace when build is done.
Prior to the checkpoint, use the stash step to save important files, such as build products. When this build is restarted from the checkpoint, all of its stashes will be copied into the new build first. You can then use the unstash step to restore some or all of the saved files into your new workspace.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With