title: Dynamically Finding File to Upload to Artifactory Jenkins Pipeline
body: <p>I have a Groovy library that takes a file at a directory and uploads it to remote host.
  The location of the artifacts to be uploaded changes dynamically. So I am trying to find the file based on regex. Here is the snippet of the code.</p>
  
  <pre><code>def file = findFiles (glob: '$WORKPLACE/**/*-${BUILD_NUMBER}-*/${file_name}.zip')
  </code></pre>
  
  <p>However, file parameter returns an empty list. Even though when I can see that the specific file I want to upload exists in the directory. 
  Is there a way to find the path to the file and use that in the function?</p>
  
  <p><strong>EDIT1</strong></p>
  
  <p>I even replaced the <code>findFiles</code> with a simple <code>ls</code>. I see the error that <code>No such file or directory</code>. But when I execute the same <code>ls</code> with the same regex I do see the file on the file system. This file gets created during the previous steps in the pipeline. Why does the future steps cannot find the file?</p>
  
  <pre><code>def file = sh (script: "ls '$WORKPLACE/**/*-${BUILD_NUMBER}-*/${file_name}.zip'", returnStdout: true).trim()
  </code></pre>
  
  <p>NOTE: The permission of the file is 644 and it is owned by Jenkins user.</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>For some reason this works. This finds the file exactly. Why is this?:</p>
  
  <pre><code>sh '''
   ls $WORKPLACE/**/*-${BUILD_NUMBER}-*/${file_name}.zip
  '''
  </code></pre>
  
  <p><strong>EDIT3</strong></p>
  
  <p>I moved the regex out of the <code>findFiles</code> just in case the variables were not substituted correctly.</p>
  
  <pre><code>  def file_path = "$WORKPLACE/**/*-${BUILD_NUMBER}-*/${file_name}.zip"
    def file = findFiles (glob: file_path)
  </code></pre>
  
  <p>I now get the following error:</p>
  
  <pre><code>java.io.IOException: Expecting Ant GLOB pattern, but saw '/app/jenkins/workspace/job/**/*-21-*/file.zip'
  </code></pre>
  
  <p>The above seems to be ant pattern. Am I missing something?</p>