I want to add to a pipeline parameters of folders and files in a directory on an agent. e.g when I click on Build with Parameters it will show my checkbox of all the folders&files at c:\project and then I can choose which files I want for the job. I try using plugin Active Choices Parameter, and to run a groovy script
node (node1){
stage('folders'){
bat "dir /b /s c:\\project"
}
}
I've tried also with powershell script
Get-ChildItem -path c:/project1 -Recurse -Name
CodePudding user response:
This plugin could be easier. Install "Filesystem List Parameter Plug-in" and set the path where to find the files.
I have this thread where i answered a similar question.
Get all managed files available for jenkins job
CodePudding user response:
You can do something like below. I don't have WIndows to test. But this should work on Windows as well. Just provide the correct Path.
pipeline {
agent any
parameters { choice(name: 'CHOICES', choices: listFiles("/var/jenkins_home/test"), description: '') }
stages {
stage('Test') {
steps {
echo "Run!!!"
}
}
}
}
@NonCPS
def listFiles(def path) {
def files= []
new File(path).traverse(type: groovy.io.FileType.FILES) { file ->
files.add(file)
}
return files
}