Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Jenkins pipeline function fileExist handle wildcards?

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?

like image 656
Mike Avatar asked Mar 10 '17 16:03

Mike


People also ask

What is wildcard in Jenkins?

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.

What is cleanWs () in Jenkins?

cleanWs : Delete workspace when build is done.

What is Stash and Unstash in Jenkins?

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.


1 Answers

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
like image 181
Christopher Orr Avatar answered Oct 22 '22 03:10

Christopher Orr