Ibtissam
Ibtissam

Reputation: 589

jenkins pipline : How to get the list of file from workspace?

In a jenkinsfile i want to get the list of files in a directory in workspace and put them in parameters. I tried with:

stage('select'){
    def workspace = pwd()
    files = []
    new File  ("$workspace/buildFile").eachFile(FileType.FILES) { files << it.name }

    BuildFile = input( id: 'userInput', message: 'Sélectionner un backup', parameters: [ [$class: 'ChoiceParameterDefinition', choices: files , description: 'Properties', name: 'param'] ])   
}

but i get message error "java.io.FileNotFoundException:"

Upvotes: 3

Views: 7164

Answers (1)

Jon S
Jon S

Reputation: 16346

The problem is that the pipeline scripts are executed on the master, so when you do new File(...) you create a file pointer on the master and not the slave/node/agent workspace context. Instead you should use findFiles which is available in the Pipeline Utility Steps plugin.

Upvotes: 5

Related Questions