2

Im using Extended Choice Parameter in Jenkins. I want to add a drop down parameter in the job and display all folder names within the given directory using a groovy script

how can i do that ?

tzlil eliyahu
  • 39
  • 1
  • 10

1 Answers1

2

You can use the following groovy script in the extended choice parameter to list all folders under a given folder (You will probably require an admin approval to run this script):

import groovy.io.FileType

def list = []

def dir = new File("/var/lib/jenkins/workspace")
dir.eachFileRecurse (FileType.DIRECTORIES) { file ->
   list << file
}
return list

However, an easier option will be to use the Filesystem List Parameter Plugin.
The plugin lists file, directory or symlink names of a defined directory and exposes them as selection options for the parameter.
It also supports include/exclude patterns and execution on different nodes .

Noam Helmer
  • 5,310
  • 1
  • 9
  • 29
  • Hi Noam, Is it possible to list files under more than one folder using the 'Filesystem List Parameter plugin'? Ex: List all text files under two child folders under a parent folder. – Vel Ganesh Nov 23 '22 at 13:32
  • I don't think the plugin currently supports multiple folder conditions. It supports only one include pattern and one exclude pattern. – Noam Helmer Nov 23 '22 at 15:55