0
votes

I am trying to create a dynamic choice parameter that will be populated by the resulting values of a groovy script.

The following code works and lists the contents of a dir:

new File("/tmp/testing/source/").eachFile() { file->  
  println file.getName()  
}

I created a new jenkins project, and entered the menu 'Configure' where I selected This project is parameterized

When I save and try to build with parameters nothing has been parsed from the groovy script

1
I think File listing is an illegal operation in Jenkins scripts, as that's a security violation (how does it know you should have access to the file system on the slave?) - billjamesdev
That is a good point. Actually the use case of this groovy code wasn't intended to list files in a directory. But it was a quick situation I came up with to demonstrate the use of active parameters. - ARL

1 Answers

2
votes

Solved with the following code:

list = []
def process = "ls /tmp/testing/source".execute()
process.text.eachLine {list.add it}
return list