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
Answer from Christopher Orr on Stack Overflow
🌐
Jenkins
jenkins.io › doc › pipeline › steps › workflow-basic-steps
Pipeline: Basic Steps
node('Linux') { if (fileExists('/usr/local/bin/jenkins.sh')) { sh '/usr/local/bin/jenkins.sh' } } node('Windows') { if (fileExists('C:/jenkins.exe')) { bat 'C:/jenkins.exe' } } When using a Windows path with the backslash ( \ ) separator, do not ...
🌐
GitHub
gist.github.com › darinpope › a2f5be7c624e76f00fbbfdab27d699a0
How-To-Check-if-a-File-Exists-Using-Jenkins.md · GitHub
pipeline { agent any stages { stage('create directory') { steps { sh 'mkdir -p src/main' } } stage('check directory') { when { expression { return fileExists('src/main') } } steps { echo "Directory src/main found!" } } } }
🌐
Baeldung
baeldung.com › home › jenkins › check if a file exists in a jenkins pipeline
Check if a File Exists in a Jenkins Pipeline | Baeldung on Ops
January 30, 2025 - We often rely on Shared Libraries in larger Jenkins setups to keep pipeline code organized. Suppose we want a standard function, checkFileExists, that can be reused across pipelines: // vars/checkFileExists.groovy in our shared library def call(String filePath) { if (fileExists(filePath)) { return true } else { return false } }
🌐
Cloudbees
support.cloudbees.com › knowledge base › pipeline with conditional stages based on a file existing on the filesystem
Pipeline with conditional stages based on a file existing on the filesystem
May 1, 2022 - Jenkins LTS · Generally this use case may not a best practise, as relying on files on a filesystem can sometimes mean you have files that are outside of source control, but there are some situations where this is valid. pipeline{ agent any environment{ MY_FILE = fileExists '/tmp/myfile' } stages{ stage('conditional if exists'){ when { expression { MY_FILE == 'true' } } steps { echo "file exists" } } stage('conditional if not exists'){ when { expression { MY_FILE == 'false' } } steps { echo "file does not exist" } } } } Pipeline: Declarative 1.3.7 Pipeline: Groovy 2.65 ·
Find elsewhere
🌐
Jenkins
issues.jenkins.io › browse › JENKINS-38855
Loading...
October 10, 2016 - 📢 Jenkins core issues have been · migrated to GitHub, no new core issues can be created in Jira · Information: This issue is archived. You can view it, but you can't modify it. Learn more · Log In · Open · Export · null · XML · Word · Printable · Type: Improvement · Resolution: Unresolved · Priority: Minor · Component/s: pipeline-utility-steps-plugin · Labels: issue-exported-to-github · Hi - it would be really nice if the fileExists() step supported file globbing: if (fileExists('foo/bar*')) { // ...
🌐
YouTube
youtube.com › watch
How To Check if a File Exists Using Jenkins - YouTube
Need help with your Jenkins questions?Visit https://community.jenkins.io/c/using-jenkins/support/8Timecodes ⏱:00:00 Introduction00:06 Overview00:12 Starting ...
Published   June 16, 2022
🌐
Stack Overflow
stackoverflow.com › questions › 16783366 › file-exist-condition-issue-in-jenkins
File Exist condition issue in Jenkins - Stack Overflow
May 28, 2013 - I am working on product testing automation. I am using Jenkins to create a job that will first browse some file in a directory. But I got a problem with Conditional Step in File Exist condition. It is not working when I search *.job file, it only works with specific file name I put.