Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "findFiles" in a Jenkinsfile?

My Jenkinsfile contains this stage:

stage('Deploy') {
    steps {
        script {
            def rpmFiles = findFiles glob: "**/*.rpm"
            def rpmFile = rpmFiles[0]
        }
    }
}

I want to use this to deploy an artifact to a server. How can I avoid the following error?

java.lang.NoSuchMethodError: No such DSL method 'findFiles' found among steps [...]
like image 733
Lalchand Mali Avatar asked Jun 04 '18 07:06

Lalchand Mali


1 Answers

While this answer isn't directly fixing the issue of the original question - the plugin wasn't installed - search engines do redirect to this question, and I found the documentation a bit lacking. So I wanted to complement the answer a bit on how to use findFiles.

As I wasn't completely satisfied by the documentation I looked at the source code and the FindFilesStep tests especially. There's one with this line in particular that showcase best how to use findFiles:

def files = findFiles(glob: '**/*.txt', excludes: 'b/*.txt,**/aba/*.txt')

As a reminder the patterns are ant style patterns. For example I wanted a task that included every file and folders but the hidden folder .asccidoctor, I wrote:

def docFiles
dir('build/docs/asciidoc/') {
    docFiles = findFiles(glob: '**', excludes: '**/.asciidoctor/**')
}
like image 161
Brice Avatar answered Sep 19 '22 09:09

Brice